一、scrollView的位置确定
scrollView位置的计算还是通过其约束进行计算的
UIScrollView *scrollview = [[UIScrollView alloc]init];
scrollview.delegate = self;
[self.view addSubview:scrollview];
[scrollview mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.view);
make.height.equalTo(@300);
}];
二、scrollView的contentSize确定
UIView *yellowView = [[UIView alloc]init];
[scrollview addSubview:yellowView];
yellowView.backgroundColor = [UIColor yellowColor];
[yellowView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.equalTo(@100);
make.height.equalTo(@500);
make.top.left.equalTo(scrollview).offset(50);
make.bottom.equalTo(scrollview.mas_bottom).offset(100);
}];
scrollView滚动内容大小由子控件的约束计算获得,对于yellowView的约束一方面决定了自己的frame,另一方面影响着contentsize的宽、高。yellowView的height决定了自身的高度,top+heigheight+bottom共同决定了contentsize的竖直滚动范围。而width+left 不能确定contentsize的水平滚动范围,视为0。因此scrollView的contentsize为CGSizeMake(0, 450)
网友评论