iOS - UIScrollView

来源:互联网 发布:mac草图大师总是卡 编辑:程序博客网 时间:2024/06/18 13:42
 [super viewDidLoad];15     16     // 1.创建UIScrollView17     UIScrollView *scrollView = [[UIScrollView alloc] init];18     scrollView.frame = CGRectMake(0, 0, 250, 250); // frame中的size指UIScrollView的可视范围19     scrollView.backgroundColor = [UIColor grayColor];20     [self.view addSubview:scrollView];21     22     // 2.创建UIImageView(图片)23     UIImageView *imageView = [[UIImageView alloc] init];24     imageView.image = [UIImage imageNamed:@"big.jpg"];25     CGFloat imgW = imageView.image.size.width; // 图片的宽度26     CGFloat imgH = imageView.image.size.height; // 图片的高度27     imageView.frame = CGRectMake(0, 0, imgW, imgH);28     [scrollView addSubview:imageView];29     30     // 3.设置scrollView的属性31     32     // 设置UIScrollView的滚动范围(内容大小)33     scrollView.contentSize = imageView.image.size;34     35     // 隐藏水平滚动条36     scrollView.showsHorizontalScrollIndicator = NO;37     scrollView.showsVerticalScrollIndicator = NO;38     39     // 用来记录scrollview滚动的位置40 //    scrollView.contentOffset = ;41     42     // 去掉弹簧效果43 //    scrollView.bounces = NO;44     45     // 增加额外的滚动区域(逆时针,上、左、下、右)46     // top  left  bottom  right47     scrollView.contentInset = UIEdgeInsetsMake(20, 20, 20, 20);48     49     _scrollView = scrollView;50 }51 52 - (IBAction)down:(UIButton *)sender {53     [UIView animateWithDuration:1.0 animations:^{54         //三个步骤55         CGPoint offset = _scrollView.contentOffset;56         offset.y += 150;57         _scrollView.contentOffset = offset;58         59         //_scrollView.contentOffset = CGPointMake(0, 0);60     }];
0 0
原创粉丝点击