[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. 
(
    "<MASLayoutConstraint:0x2834265e0 UILabel:0x100d33a40.left == UIView:0x100d192a0.left + 4>",
    "<MASLayoutConstraint:0x283426640 UILabel:0x100d33a40.right == UIView:0x100d192a0.right - 4>",
    "<NSLayoutConstraint:0x283316120 UIView:0x100d192a0.width == 1>"
)

Will attempt to recover by breaking constraint 
<MASLayoutConstraint:0x283426640 UILabel:0x100d33a40.right == UIView:0x100d192a0.right - 4>

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

我的约束是这么写的:

看起来没啥问题,但是貌似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));
}];

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值