使用Masonry,对scrollView进行布局的问题
scrollView使用自动约束是要特别小心,使用自动约束之后,scrollView.contentSize会根据它的subviews来进行计算,所以一定要保证添加到scrollView里的subview的宽高是可以确定的值,并且要和scrollView的edge进行正确的约束。
[self.view addSubview:self.scrollView];
[self.scrollView addSubview:view1];
[self.scrollView addSubview:view2];
[self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.bottom.right.equalTo(self.view);
}];
[view1 mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.bottom.equalTo(self.scrollView);
make.width.equalTo(self.view.mas_width);
make.height.equalTo(self.view.mas_height);
}];
[view2 mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(view1.mas_right);
make.top.and.bottom.and.right.equalTo(self.scrollView);
make.width.equalTo(self.view.mas_width);
make.height.equalTo(self.view.mas_height);
}];
网友评论