当在scrollview上添加子控件并用masonry布局时,发现运行后不是想要的布局,解决方法是需要添加一个view,上下左右,宽高。都要和scrollview一致。然后再在view上添加子控件即可。
UIScrollView *scrollView = [[UIScrollView alloc] init];
[self.view addSubview:scrollView];
[scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
UIView *backView = [[UIView alloc] init];
[scrollView addSubview:backView];
backView.backgroundColor = [UIColor clearColor];
[backView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(scrollView);
make.height.width.equalTo(scrollView);
}];
UIView *btnView = [[UIView alloc] init];
[backView addSubview:btnView];
btnView.backgroundColor = [UIColor whiteColor];
[btnView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.right.equalTo(backView);
}];