masonry为scrollerview的子视图添加约束

1UIScrollView添加AutoLayout约束的坑

综上所属:
scrollView内部的子控件的约束必须完整

代码如下:

- (UIScrollView *)hScrollerView{
    if (!_hScrollerView) {
        _hScrollerView = [[UIScrollView alloc] init];
        _hScrollerView.pagingEnabled = YES;
        _hScrollerView.showsHorizontalScrollIndicator = YES;
    }
    return _hScrollerView;
}

添加约束:

    [self.hScrollerView addSubview:self.passwordLoginBackView];
    [self.hScrollerView addSubview:self.noPasswordLoginBackView];
      [self.hScrollerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.segement.mas_bottom);
        make.left.right.bottom.equalTo(self);
    }];

    [self.passwordLoginBackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.left.equalTo(self.hScrollerView);
        make.width.height.equalTo(self.hScrollerView);
    }];
    [self.noPasswordLoginBackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.passwordLoginBackView.mas_right);
        make.top.right.bottom.equalTo(self.hScrollerView);
        make.width.height.equalTo(self.hScrollerView);
    }];

并不需要声明contentsize属性,scrollerview确实是可以滑动的~

竖直方向只需要一条完整的贯穿上下的约束即可

水平方向只需要一条完整的贯穿左右的约束即可

你可能感兴趣的:(masonry为scrollerview的子视图添加约束)