UIScrollView 知识

- (void)viewDidLoad {

    [super viewDidLoad];

    

//    [self firstUIScrollView];

    [self secondUIScrollView];

}

// 给定的frame 正常的显示 

- (void)firstUIScrollView{

    

    UIScrollView *firstScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 100,kScreenWidth , 300)];

    

//One

    firstScroll.contentOffset = CGPointMake(kScreenWidth , 100);

    firstScroll.contentSize = CGSizeMake(kScreenWidth * 3, 300);// 内容的大小

    //firstScroll.contentInset = UIEdgeInsetsMake(10, 20, 30, 40);

    // 滑动锁定  左右滑动的同时不可以上下滑动  反之也是

    firstScroll.directionalLockEnabled = YES;

    //bounces 是否有弹簧效果

    firstScroll.bounces = YES;

    firstScroll.alwaysBounceVertical = YES;

    firstScroll.pagingEnabled = YES;// 分页效果

    // yes--> 可以滑动   no---> 不可以滑动

    firstScroll.scrollEnabled = YES;

    // 显示水平滑动条  no ---> 不显示   yes  ---> 显示

    firstScroll.showsHorizontalScrollIndicator = YES;

    // 显示垂直滑动条

    firstScroll.showsVerticalScrollIndicator = YES;

    // 指示条的位置

    firstScroll.scrollIndicatorInsets = UIEdgeInsetsMake(10, 20, 30, 40);

    // 它的值域是(0.01.0

    firstScroll.decelerationRate = 1.0;

    

//Two

    // tracking  touch后还没有拖动的时候值是YES,否则NO

    if (firstScroll.tracking) {

        

        NSLog(@"tracking = yes");

    }

    else{

        NSLog(@"tracking = no");

    }

    

    

    firstScroll.minimumZoomScale = 0.1;

    firstScroll.maximumZoomScale = 1.0;

    

    firstScroll.backgroundColor = [UIColor cyanColor];

    [self.view addSubview:firstScroll];

    

    NSArray *array = @[@"two",@"one",@"two"];

    for (int i = 0; i<3; i++) {

        UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(i*kScreenWidth, 0, kScreenWidth,300)];

        imageV.image = [UIImage imageNamed:[array objectAtIndex:i]];

        [firstScroll addSubview:imageV];

    }

}

 

 // 使用自动约束

- (void)secondUIScrollView{

    

    

    //initWithFrame:CGRectMake(0, 100,kScreenWidth , 300)

    UIScrollView *second = [[UIScrollView alloc] init];

    second.translatesAutoresizingMaskIntoConstraints = NO;

    

    second.contentOffset = CGPointMake(kScreenWidth, 100);

    second.contentSize = CGSizeMake(kScreenWidth * 3, 400);

    second.pagingEnabled = YES;

    second.backgroundColor = [UIColor redColor];

    [self.view addSubview:second];

    

    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[second]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(second)]];

    

    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-100-[second(400)]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(second)]];

    // 图片名字放在数组中

    NSArray *array = @[@"two",@"one",@"two"];

    for (int i = 0; i<3; i++) {

        UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(i*kScreenWidth, 0, kScreenWidth,400)];

        imageV.image = [UIImage imageNamed:[array objectAtIndex:i]];

        [second addSubview:imageV];

    }

 

    

    

}

 

posted @ 2016-05-05 18:14  徒步阳光855  阅读(127)  评论(0编辑  收藏  举报