往scrollVIew中添加一個按鈕,直接報錯
專門的view,作容器去確定scrollView滾動范圍
水平滾動范圍:view的寬度 + 左右兩邊間距
垂直滾動范圍:view的高度 + 上下兩邊的間距
scrollView自動布局——代碼約束
[scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view).offset(64);
make.left.bottom.right.offset(0);
}];
- 給里面的容器
contentView
設置寬高
約束
- 用專門的view確定scrollView的滾動范圍
[self.scrollView addSubView:self.contentView];
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.offset(0);
// 這句話不加有問題!因為沒有設置scrollView的寬度
make.width.equalTo(self.view*3);
make.height.mas_equalTo(800);
}];
- contentView把滾動視圖撐起來,它的寬高決定了
scrollView
的contentSize
的width
和height
- 以后所有子控件都添加到
contentView容器
里,都基于contentView
來布局
-
bounds = NO
就是一個滾動的view
,沒彈簧效果
edge
補充
// make top, left, bottom, right equal view2
make.edges.equalTo(view2);
// make top = superview.top + 5, left = superview.left + 10,
// bottom = superview.bottom - 15, right = superview.right - 20
make.edges.equalTo(superview).insets(UIEdgeInsetsMake(5, 10, 15, 20))
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。