UIScrollVIew

weixin_34050427發表於2016-11-14

初始化

@property (nonatomic, strong) UIScrollView *scroll;
- (UIScrollView *)scroll{
    if(!_scroll){
        _scroll=[[UIScrollView alloc] init];
        _scroll.contentSize=CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT *2);
        _scroll.backgroundColor = [UIColor grayColor];
        _scroll.delegate = self;
        _scroll.bounces = NO;
    }
    return _scroll;
}

[self.view addSubview:self.scroll];
[_scroll mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
 }];

方法&屬性

##控制控制元件遇到邊框是否反彈(預設為YES)
_scroll.bounces = NO;
##控制控制元件是否整頁翻動(預設為NO)
_scroll.pagingEnabled = YES;
##控制控制元件是否能滾動(預設為YES)
_scroll.scrollEnabled = YES;
##控制是否顯示垂直方向的滾動條(預設為YES)
_scroll.showsVerticalScrollIndicator = YES;
##控制是否顯示水平方向的滾動條(預設為YES)
_scroll.showsHorizontalScrollIndicator = YES;
##滾動到指定位置(預設CGPointZero)
 [_scroll setContentOffset:CGPointMake(0, 200) animated:YES];

常用代理方法

##scrollView滾動時,就呼叫該方法。即滾動過程中,呼叫多次

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    CGPoint point=scrollView.contentOffset;
    NSLog(@"%f,%f",point.x,point.y);

}

其他屬性
##-----介面中有UIScrollView的話,點選狀態列會讓其滾動到頂部

利用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

相關文章