UIScrollView自动布局

往scrollVIew中添加一个按钮,直接报错
专门的view,作容器去确定scrollView滚动范围
水平滚动范围:view的宽度 + 左右两边间距
垂直滚动范围:view的高度 + 上下两边的间距

scrollView自动布局——代码约束

  • 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把滚动视图撑起来,它的宽高决定了scrollViewcontentSizewidthheight
  • 以后所有子控件都添加到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))
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • iOS_autoLayout_Masonry 概述 Masonry是一个轻量级的布局框架与更好的包装AutoLay...
    指尖的跳动阅读 1,195评论 1 4
  • (一)Masonry介绍 Masonry是一个轻量级的布局框架 拥有自己的描述语法 采用更优雅的链式语法封装自动布...
    木易林1阅读 2,390评论 0 3
  • Masonry是一个轻量级的布局框架,拥有自己的描述语法,采用更优雅的链式语法封装自动布局,简洁明了并具有高可读性...
    3dcc6cf93bb5阅读 1,828评论 0 1
  • Masonry手写Autolayout专题 Masonry介绍与使用实践:快速上手Autolayout http:...
    Kevin_Junbaozi阅读 1,177评论 0 2
  • 暖气开到最大,车内有点闷热。车窗外远山带着斜阳,红霞弥弥。高速公路上的路灯一口气全亮了。
    吾苏晴溪阅读 153评论 0 1