[self.view addSubview:self.scrollView];
[self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view.mas_top).with.offset(.0);
make.left.equalTo(self.view.mas_left).with.offset(0.0);
make.right.equalTo(self.view.mas_right).with.offset(0.0);
make.bottom.equalTo(self.view.mas_bottom).with.offset(0.0);
}];
[self.scrollView addSubview:self.contentView];
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.scrollView);
make.width.equalTo(self.scrollView);
}];
[self.contentView addSubview:self.cycleScrollView];
[self.cycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentView.mas_top).with.offset(.0);
make.left.equalTo(self.contentView.mas_left).with.offset(0.0);
make.right.equalTo(self.contentView.mas_right).with.offset(0.0);
make.height.equalTo(@(SCREEN_WIDTH/3));
}];
[self.contentView addSubview:self.collectionView];
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.cycleScrollView.mas_bottom).with.offset(5.0);
make.left.equalTo(self.contentView.mas_left).with.offset(5.0);
make.right.equalTo(self.contentView.mas_right).with.offset(-5.0);
make.height.equalTo(@(self.collectionViewCellHight * number));
}];
[self.contentView addSubview:self.tableView];
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.collectionView.mas_bottom).with.offset(5.0);
make.left.equalTo(self.contentView.mas_left).with.offset(5.0);
make.right.equalTo(self.contentView.mas_right).with.offset(-5.0);
make.height.equalTo(@(SCREEN_WIDTH/3 * [self.categoryItems count] + HEADERVIEWHIGHT));
}];
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.tableView.mas_bottom).with.offset(50.0);
}];
和砌体警告:
Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
"<MASLayoutConstraint:0x7f93031d8880 UITableView:0x7f930489b800.height == 415>",
"<MASLayoutConstraint:0x7f930342c990 UITableView:0x7f930489b800.height == 290>"
)
Will attempt to recover by breaking constraint
我在scrollview中创建了一个contentView,在contentView中创建了所有其他视图。但是collectionView和tableView的高度将会改变,
所以这样做的结果出错了。我的问题是当子视图的高度发生变化时,我该怎么做才能解决这个问题? 谢谢你。
编辑:
当tableview的数据源发生变化时,从2变为3,但是tableview的高度没有显示正确的高度。
答案 0 :(得分:1)
我没有使用过Masonry-iOS-OSX,但就autolayout而言,不要给滚动视图的高度(当你将滚动视图连接到超级视图的顶部和底部时这样做),它的高度应该取决于内部视图。删除滚动视图的顶部和底部约束,并将对齐中心放置到超级视图。这样当集合视图的高度发生变化时,它将改变滚动视图的高度。 希望它能解决你的问题。