一般当我们在做手机页面视图的时候,往往会考虑到将view加载到scrollview上,这样,当页面内容足够多的时候,就可以上下滑动,不至于内容显示不完整这个时候,view的视图布局往往这样处理(布局采用Mansory):
1.先创建scrollview,让scrollview的尺寸和屏幕一样大小,
[scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
2.再创建scrollview的内部view,让contentview去填充scrollview,这个时候contentview的尺寸切记不要设置高度
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.contentScrollView);
make.width.equalTo(self.contentScrollView);
}];
3.然后我们页面内部的小控件UI就可以加载到contentview上,这里提示,所加的控件,均要设置height。如果contentview添加了最后一个视图,也就是最底部的view后(这里是页面上下滑动),这个时候,最后一个view约束一定要设置bottom属性
[self.bottomConfirmView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.contentView);
make.top.equalTo(self.tableView.mas_bottom);
make.height.mas_offset(50);
//一定要添加
make.bottom.equalTo(self.contentView).with.offset(-10);
}];
这样所有视图就都被包装在了contentView里。
tip: make.bottom.equalTo(self.contentView).with.offset(-10);设置这个约束是让界面可以滑动。
当我们设置禁止 scrollview向上滑动时候,在scrollViewDidScroll代理方法中:
if (scrollView.contentOffset.y >0) {
scrollView.contentOffset = CGPointMake(scrollView.contentOffset.x, 0);
}
网友评论