ios 约束冲突NSAutoresizingMaskLayoutConstraint

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:0x7fafcb1c8e10 UIButton:0x7fafcb18e160.width == UIView:0x7fafcb0bd380.width - 60>",
    "<NSAutoresizingMaskLayoutConstraint:0x7fafcb0a2570 UIView:0x7fafcb0bd380.width == 0>"
)

Will attempt to recover by breaking constraint 
<MASLayoutConstraint:0x7fafcb1c8e10 UIButton:0x7fafcb18e160.width == UIView:0x7fafcb0bd380.width - 60>

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.

在手撸约束的时间,经常会碰到类似的约束警告,其实对布局显示是没有影响的,但是看到这个警告真是蛋疼的要死啊,整个人的心情都不好了,怎么办?谷歌百度啊。

结果如下:

当你决定在你的项目中大规模使用AutoLayout时,那么NSAutoresizingMaskLayoutConstraint大部分情况下是非常不和谐的东西,它通常会把你的程序搞崩溃,幸好IB中的View不会出现这个问题,如果你使用代码添加了view并且出现了NSAutoresizingMaskLayoutConstraint相关的问题,你应该将该View的translatesAutoresizingMaskIntoConstraints设置为NO。

再次编辑,又遇到了这个扯淡的问题,按照上面的方法,可以消除警告,但是现实的宽度不对了。

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px}span.s1 {font-variant-ligatures: no-common-ligatures}span.Apple-tab-span {white-space:pre}

**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) **
**(**
**    "<NSLayoutConstraint:0x7fdfc403ec90 MeHeadView:0x7fdfc4069730.trailing == UILabel:0x7fdfc40900d0.trailing + 20>",**
**    "<NSLayoutConstraint:0x7fdfc40a8210 UILabel:0x7fdfc40900d0.leading == MeHeadView:0x7fdfc4069730.leading + 20>",**
**    "<NSLayoutConstraint:0x7fdfc1d6c250 MeHeadView:0x7fdfc4069730.width == 0>"**
**)**
****
**Will attempt to recover by breaking constraint **
**<NSLayoutConstraint:0x7fdfc403ec90 MeHeadView:0x7fdfc4069730.trailing == UILabel:0x7fdfc40900d0.trailing + 20>**
****
**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.**

先修改如下


Paste_Image.png

把其中一个关于superview的约束从Required修改为High,就可以了;既消除了警告,也不影响视图的现实。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值