一、问题发生
用Masonry 来写UITableview的高度自动计算的时候。UITableViewCell 里面放置了一个UIImageView,这个UIImageView 跟cell 上下左右差距10个像素,
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.contentView).with.inset(10);
}];
会出现警告:
[LayoutConstraints] 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:0x6000002a3cc0 UIImageView:xxxxxxxxx.top == UITableViewCellContentView:0x7fe202c2a050.top + 10>",
"<MASLayoutConstraint:0x6000002a3d80 UIImageView:xxxxxxxxx.bottom == UITableViewCellContentView:0x7fe202c2a050.bottom - 10>",
"<MASLayoutConstraint:0x6000002a5820 UIImageView:xxxxxxxxx.height == 132.5>",
"<NSLayoutConstraint:0x600000286c70 UITableViewCellContentView:0x7fe202c2a050.height == 43.5>"
)
看到这个警告的时候,猜测原因是因为一开始Cell创建的时候,设置了上下左右的高度,但是由于bottom - top的高度小于UIImageView的高度。这时候UIimageView的高度又依赖于cell的高度来调整。就会出现这个警告。
上网查了一个,碰到这个问题的人不在少数,最后的解决方案是改成
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.contentView).with.inset(10).priority(MASLayoutPriorityDefaultLow);
}];
通过降低优先级的办法来达到。这样警告就会消失。