[LayoutConstraints] Unable to simultaneously satisfy constraints.

在项目中会看到打印台上有这样的警告:

2023-05-25 10:04:41.811357+0800 JDDDemo[23487:9760518] [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. 
(
    "",
    "",
    ""
)

Will attempt to recover by breaking constraint 


Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in  may also be helpful.

我的约束是这么写的:

[LayoutConstraints] Unable to simultaneously satisfy constraints._第1张图片

看起来没啥问题,但是貌似masonary给contentView添加了一个默认的约束width=1,然后我自己想要的约束是这个label要距contentView左右边距是4,那就是说这个contentView的宽度至少不小于8,这样就和系统默认的约束width=1相冲突了。

然后看网上的解决办法是设置一个优先级:

[label mas_makeConstraints:^(MASConstraintMaker *make) {
      make.top.equalTo(@0);
      make.left.equalTo(@4);
      make.right.equalTo(@(-4)).priorityHigh();
      make.bottom.equalTo(@0).priorityHigh();
      make.height.equalTo(@(height_tags));
}];

或者

[label mas_makeConstraints:^(MASConstraintMaker *make) {
       make.top.equalTo(@0);
       make.left.equalTo(@4);
       make.right.equalTo(@(-4)).priority(999);
       make.bottom.equalTo(@0).priority(999);
       make.height.equalTo(@(height_tags));
}];

这样就可以消除掉打印台上的警告了

你可能感兴趣的:(ios)