Masonary与UIScrollView一起使用方案
UIScrollView *scrollView = [[UIScrollView alloc] init];
scrollView.userInteractionEnabled = YES;
scrollView.scrollEnabled = YES;
scrollView.backgroundColor = [UIColor greenColor];
[self.view addSubview:scrollView];
[scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
UIView *containView = [UIView new];
containView.backgroundColor = [UIColor redColor];
[scrollView addSubview:containView];
[containView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(scrollView);
make.width.equalTo(scrollView);
//如果可以左右滑动,正好是屏幕宽度的2倍
//make.width.equalTo(scrollView).multipliedBy(2);
}];
UIView *subView = [UIView new];
subView.backgroundColor = [UIColor blueColor];
[containView addSubview:subView];
[subView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(containView).with.offset(50);
make.top.equalTo(containView).with.offset(self.view.height*1.2);
make.size.mas_equalTo(CGSizeMake(50, 50));
}];
[containView mas_updateConstraints:^(MASConstraintMaker *make) {
//这个约束,决定了containView的高,间接决定了scrollview的ContentSize的高
//当subview比较靠上时,也有下拉上拉回弹效果
make.bottom.equalTo(subView).with.offset(10).priority(999);
make.height.greaterThanOrEqualTo(@(self.view.bounds.size.height+1))
}];
```
[exmple](https://github.com/SnapKit/Masonry/blob/master/Examples/Masonry%20iOS%20Examples/MASExampleScrollView.m)