UIScrollView
通常称为滚动视图,我们可以用它来实现很多的效果,如图片浏览,图片缩放,添加定时器后可以制作成图片轮播器等等
UIScrollView *scrollView = [UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 200, 200);
UIImageView *imgView = [UIImageView alloc] initWithImage:[UIImage imageNamed:@"1.jpg"];
[scrollView addSubview:imgView];
scrollView.contentSize = imgView.image.size;
scrollView.bounces = YES;
scrollView.scrollEnabled = YES;
scrollView.userInteractionEnabled = YES;
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = YES;
scrollView.alwaysBounceHorizontal = YES;
scrollView.alwaysBounceVertical = YES;
scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite; // 设置滚动条的样式
可以利用setContentOffset:offset animated:YES
方法设置偏移量, 达到在点击按钮切换视图的目的
contentInset
objc self.tableView.contentInset = UIEdgeInsetsMake( 100, 0, 0, 0); // UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right):上左下右
注意查看PPT中的对比图理解: contentSize/contentOffset/contentInset/frame
设置偏移时带有动画效果
- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated; // animate at constant velocity to new offset
原文:http://www.cnblogs.com/wxdonly/p/5118404.html