在使用Masonry时候,有时候虽然界面显示正常,但是log里面会出现如下类似的警告。
一.问题描述:
[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:0x600002e4db00 UIImageView:0x7f8510f5ec00.left == OTCMyHeaderView:0x7f8510d11da0.left + 14>,
<MASLayoutConstraint:0x600002e4db60 UIImageView:0x7f8510f5ec00.right == OTCMyHeaderView:0x7f8510d11da0.right - 14>,
<NSLayoutConstraint:0x600002962080 OTCMyHeaderView:0x7f8510d11da0.width == 0>
]
Will attempt to recover by breaking constraint
<MASLayoutConstraint:0x600002e4db60 UIImageView:0x7f8510f5ec00.right == OTCMyHeaderView:0x7f8510d11da0.right - 14>
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.
二. 解决方法:
1.通过断点找到有问题的控件XX
2. 初始化控件XX 下面 添加 代码 MASAttachKeys(控件XX)
3.run,看log
一目了然就可以看到有问题的约束,修改即可。