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.通过断点找到有问题的控件XX

2. 初始化控件XX 下面 添加 代码   MASAttachKeys(控件XX), 可以传多个控件

3.run,看log

可以显示出控件的名字,一目了然就可以看到有问题的控件约束,修改即可。

布局太复杂, 不好确认是哪个空间, 还有一种方法

1.先点击Debug View Hierarchy

2.打印页控件层级和地址

OC使用

po [[UIWindow keyWindow] _autolayoutTrace]

Swift使用 

expr -l objc++ -O -- [[UIWindow keyWindow] _autolayoutTrace]

3.搜索报错的地址0x111e168f0,定位到错误控件 

断点小技巧:



链接:https://www.jianshu.com/p/838b012f12a0

https://www.jianshu.com/p/5c231afb91fa

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值