我在我的UITableViewCell
中使用Masonry,單元格有兩個子視圖,一個是contentLabel
,另一個是imageView
。 雖然imageView
並不總是存在,但如果單元格有一個圖像url,顯示它或隱藏。如果imageView
是隱藏的,我想給contentLabel
設置爲cell.contentView.bottom
另一個值,東西象下面這樣:mas_updateConstraints沒有去除砌體中的約束條件
[_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView.mas_left);
make.top.equalTo(self.contentView.mas_bottom).offset(20);
make.right.equalTo(self.contentView.mas_right).offset(-6);
_bottomConstraint = make.bottom.equalTo(_imageView.mas_top).offset(-14);
}];
[_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_contentLabel.mas_left);
make.bottom.equalTo(self.contentView.mas_bottom).offset(-14);
}];
if (tweet.imageUrl) {
_imageView.hidden = NO;
[_imageView sd_setImageWithURL:tweet.imageUrl placeholderImage:[UIImage imageNamed:@"loading"] options:0];
} else {
_imageView.hidden = YES;
[_imageView sd_setImageWithURL:NULL];
}
if (_imageView.hidden) {
[_contentLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(_imageView.mas_top).offset(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. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<MASLayoutConstraint:0x7fef9cd178d0 UILabel:0x7fef9cd437e0.bottom == UIImageView:0x7fef9cd26260.top - 14>",
"<MASLayoutConstraint:0x7fef9caf5430 UILabel:0x7fef9cd437e0.bottom == UIImageView:0x7fef9cd26260.top>"
)
Will attempt to recover by breaking constraint
<MASLayoutConstraint:0x7fef9caf5430 UILabel:0x7fef9cd437e0.bottom == UIImageView:0x7fef9cd26260.top>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
這似乎mas_updateConstraints
沒」刪除舊的約束,但添加一個新的約束,兩者相互衝突。那麼我怎麼能在運行時動態地更新約束值呢?
面臨着同樣的問題,明確不幫:( – trickster77777
同樣在這裏,我必須存放在約束屬性進行更新和「更新」之前卸載它。如果不卸載,我有兩個相互矛盾的制約。一個乾淨的構建呢沒有幫助。 –