Masonry UIScrollView 动态高度

  1. 创建 UIScrollView
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
    [self.view addSubview:scrollView];

    [scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).with.offset(kTitleHeight);
        make.left.right.equalTo(self.view);
        make.bottom.equalTo(self.view);
    }];

2.创建 ViewContiner ,作为 scrollView 唯一 subView

    UIView *viewContainer = [UIView new];
    [scrollView addSubview:viewContainer];

    [viewContainer mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(scrollView);
        make.width.equalTo(scrollView);
    }];

3.其他 View 作为 ViewContainer 的 subView;

   [viewContainer  addSubView:..];

4.ViewContainer 最下方的 subView(通常为分割线) 设置 bottom

    [split  mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_forumTitleLabel.mas_bottom).with.offset(7);
        make.left.right.equalTo(_forumTitleLabel); // _forumTitleLabel split 上方的 View
        make.bottom.equalTo(viewContainer);// (重点)
    }];

猜你喜欢

转载自blog.csdn.net/stupid56862/article/details/80543651