@property(nonatomic) CGPoint contentOffset; // default CGPointZero
@property(nonatomic) CGSize contentSize; // default CGSizeZero
@property(nonatomic) UIEdgeInsets contentInset; // default UIEdgeInsetsZero. add additional scroll
- contentInset相当于给内容物加一个边框。(边框不计入contentSize中)
- contentOffset设置(获取)内容物偏移位置(不包含contentInset)
Storyboard和xib连线
连线的控件会调用setter方法。
从storyboard中加载,在viewDidLoad之前执行
-(void) setScrollView:(UIScrollView *)scrollView
{
_scrollView = scrollView;
}
缩放
-(UIView *)viewForZoomingInScrollerView:(UIScrollerView *)scrollView
{
//告诉scrollView需要缩放哪个view
return self.imageView;
}
设置最大最小缩放比例
self.scrollView.maximumZoomScale = 2.0;
self.scrollView.minimumZoomScale = 0.2;
//self.scrollView.transform --> 通过transform实现缩放的
分页
self.scrollView.pagingEnabled = YES;
弹簧效果
self.scrollView.bounces = YES;
配合分页控件
UIPageControl *page = [[UIPageControl alloc] init];
numberOfPages
currentPage
设置大小
CGSize size =[ page sizeForNumberOfPages:5];
page.bounds = CGRectMake(0, 0, size.width, size.height);
page.center = ...;
设置颜色
page.pageIndicatorTintColor
page.currentPageIndicatorTintColor
分页控制器添加监听方法
page addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
动画效果切换
[page setContentOffset:.. animated:YES];