1、如果出现约束冲突(如下提示),检查是不是给错误的视图加了约束:
[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:0x600000e32640 UIImageView:0x7f8155416420.top == UIView:0x7f8155415f60.top>",
"<MASLayoutConstraint:0x600000e33840 UIImageView:0x7f8155418780.top == UIImageView:0x7f8155416420.bottom + 55>",
"<MASLayoutConstraint:0x600000e345a0 UIView:0x7f8155415f60.centerY == UIImageView:0x7f8155418780.centerY>",
"<MASLayoutConstraint:0x600000e34720 UIView:0x7f8155415f60.height == 14>"
)
原代码如下,原本应该给self.nameLabel添加约束,它的父视图是UICollectionViewCell.contentView,结果错误地给其父视图加了约束。
self.nameLabel = [[UILabel alloc] init];
self.nameLabel.font = [UIFont systemFontOfSize:10];
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.avatarImageView.mas_right).offset(6);
make.right.equalTo(self.coverImageView);
make.centerY.equalTo(self.avatarImageView);
make.height.equalTo(@(self.nameLabel.font.lineHeight));
}];