如何查找导致'Unable to simultaneously satisfy constraints'的视图



有时我会遇到布局问题,但我不确定是哪个视图在发送它

2020-07-17 18:46:00.243783+0200 your-app[97175:3182603] [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. 
(
"<NSLayoutConstraint:0x600003a76d00 UIView:0x7f967ff233d0.width == - 16   (active)>"
)
Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600003a76d00 UIView:0x7f967ff233d0.width == - 16   (active)>
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:等待错误记录

做任何导致错误记录的事情,当它看到这样的信息时:

<NSLayoutConstraint:0x600003a76d00 UIView:0x7f967ff233d0.width == - 16   (active)>

从这里,注意视图的内存地址,在本例中为0x7f967ff233d0

步骤2:暂停应用程序

在控制台上方的xcode中,点击暂停按钮,应用程序停止,我们可以输入lldb命令

步骤3:与内存地址交互

既然我们有了内存地址,我们就可以针对它运行一些东西,例如:

日志对象:

expr -l objc -O -- 0x7f967ff233d0

日志属性:

expr -l objc -O -- [0x7f967ff233d0 someProperty]

实时更改背景色

我找到我的方法是,你可以对这个对象实时执行代码,使用这个,我们可以将背景颜色设置为明显的颜色,并在视觉上识别。

expr -l objc -O -- [0x7f967ff233d0 setBackgroundColor: [UIColor blueColor]]

从那里,只需单击播放,即可直观地找到问题视图。

相关内容

最新更新