iOS 使用Masonry出现约束警告问题

在使用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

二. 解决方法:

1.通过断点找到有问题的控件XX

2. 初始化控件XX 下面 添加 代码   MASAttachKeys(控件XX)

2

3.run,看log

3

一目了然就可以看到有问题的约束,修改即可。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。