初始化
@property (nonatomic, strong) UIScrollView *mScrollView;
- (UIScrollView *)mScrollView{
if(!_mScrollView){
UIScrollView *scrollView=[[UIScrollView alloc] init];
scrollView.contentSize=CGSizeMake(SCREEN_WIDTH*2, SCREEN_HEIGHT);
scrollView.backgroundColor = [UIColor grayColor];
scrollView.delegate = self;
scrollView.bounces = NO;
scrollView.pagingEnabled = YES;
_mScrollView = scrollView;
}
return _mScrollView;
}
[self.view addSubview:self.mScrollView];
[self.mScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
方法&属性
##控制控件遇到边框是否反弹(默认为YES)
scrollView.bounces = NO;
##控制控件是否整页翻动(默认为NO)
scrollView.pagingEnabled = YES;
##控制控件是否能滚动(默认为YES)
scrollView.scrollEnabled = YES;
##控制是否显示垂直方向的滚动条(默认为YES)
scrollView.showsVerticalScrollIndicator = YES;
##控制是否显示水平方向的滚动条(默认为YES)
scrollView.showsHorizontalScrollIndicator = YES;
##滚动到指定位置(默认CGPointZero)
[scrollView setContentOffset:CGPointMake(0, 200) animated:YES];
##取消向下偏移 64/20
if(@available(iOS 11.0, *)) {
self.mScrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}else {
self.automaticallyAdjustsScrollViewInsets = NO;
}
常用代理方法
##scrollView滚动时,就调用该方法。即滚动过程中,调用多次
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
CGPoint point=scrollView.contentOffset;
NSLog(@"%f,%f",point.x,point.y);
}
其他属性
##-----界面中有UIScrollView的话,点击状态栏会让其滚动到顶部
UIScrollView 嵌套 UITableView
https://www.jianshu.com/p/ec096a7d3a09
利用Storyboard给UIScrollView添加约束
https://www.jianshu.com/p/39bef1487814
UIScrollView总结
https://www.jianshu.com/p/2c74b7a6c082
http://www.cnblogs.com/liuting-1204/p/5960815.html
https://www.cnblogs.com/jackma86/p/4976683.html