Day.03.04 UIScrollView 滑动视图

#import "ViewController.h"

#define KScreenW [UIScreen mainScreen].bounds.size.width
#define KScreenH [UIScreen mainScreen].bounds.size.height

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    /*——————————————————————————UIScrollView 滑动视图————————————————————————————————————————————————————-*/

    //1.创建
    UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 20, KScreenW, KScreenW)];
    
    scrollView.backgroundColor = [UIColor grayColor];
    
    [self.view addSubview:scrollView];
    
    //2.
        //1.尺寸
    scrollView.contentSize = CGSizeMake(5 * KScreenW, KScreenW);
    
        //2.是否开启分页 默认NO
    scrollView.pagingEnabled = YES;
    
        //3.是否开启滚动条 默认YES
            //水平
    scrollView.showsHorizontalScrollIndicator = YES;
            //垂直
    scrollView.showsVerticalScrollIndicator = NO;
    
        //4.滑动条样式
    /**
     *
     UIScrollViewIndicatorStyleDefault,     // black with white border. good against any background 系统默认滑动条
     UIScrollViewIndicatorStyleBlack,       // black only. smaller. good against a white background 黑色的滑动条
     UIScrollViewIndicatorStyleWhite        // white only. smaller. good against a black background 白色的滑动条
     */
    scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
    
        //5.是否开启首位反弹效果 默认YES
            //滑动
    scrollView.bounces = YES;
            //缩放
    scrollView.bouncesZoom = YES;
    
        //6.是否开启滚动 默认YES
    scrollView.scrollEnabled = YES;
    
        //7.item的偏移量
//    scrollView.contentInset = UIEdgeInsetsMake(0, 50, 0, 50);
    
        //8.content 的偏移量
//    scrollView.contentOffset = CGPointMake(2*KScreenW, 0);
        //两秒后才偏移
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [scrollView setContentOffset:CGPointMake(2 *KScreenW, 0) animated:YES];
    });
    
    
    
    
    //获取图片
    for (int i = 0; i < 5; i++) {
        //获取照片
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"scene%d.jpg",i+1]];
        
                                                                //imageView的大小
        UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(i* KScreenW, 0, KScreenW, KScreenW)];
        
        //把图片放入图片视图
        imageV.image = image;
        
        //把图片视图放入scrollView里
        [scrollView addSubview:imageV];
        
    }
}
@end

Day.03.04 UIScrollView 滑动视图_第1张图片
屏幕快照 2016-03-04 下午4.28.36.png

你可能感兴趣的:(Day.03.04 UIScrollView 滑动视图)