在Xcode的调试控制台输出中禁用自动布局约束错误消息

时间:2015-07-06 07:24:10

标签: ios xcode autolayout

有没有办法(暂时)禁用自动布局错误/警告信息:

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:0x170098420 H:[UIView:0x15c62c100(2)]>",
    "<NSLayoutConstraint:0x170098600 UIView:0x15c6294f0.leading == UIView:0x15c628d40.leadingMargin - 8>",
    "<NSLayoutConstraint:0x170098650 H:[UIView:0x15c6294f0]-(0)-[UIView:0x15c62b750]>",
    "<NSLayoutConstraint:0x1700986a0 UIView:0x15c62b750.width == UIView:0x15c6294f0.width>",
    "<NSLayoutConstraint:0x1700986f0 UIView:0x15c628d40.trailingMargin == UIView:0x15c62b750.trailing - 8>",
    "<NSLayoutConstraint:0x170098880 H:[UIView:0x15c6294f0]-(0)-[UIView:0x15c62c100]>",
    "<NSLayoutConstraint:0x1700988d0 UIView:0x15c628d40.centerX == UIView:0x15c62c100.centerX + 1>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x170098420 H:[UIView:0x15c62c100(2)]>

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.

5 个答案:

答案 0 :(得分:148)

做了一些反编译,实际上有一种方法:

for Swift 3

 UserDefaults.standard.setValue(false, forKey: "_UIConstraintBasedLayoutLogUnsatisfiable")

目标-C

[[NSUserDefaults standardUserDefaults] setValue:@(NO) forKey:@"_UIConstraintBasedLayoutLogUnsatisfiable"];

现在,您只会收到通知&#34; _UIConstraintBasedLayoutLogUnsatisfiable为OFF&#34;。

对于阅读此内容的任何人的强制性提醒:这应该是最后的手段,有关调试和修复约束问题的提示,请参阅WWDC&#34;自动布局之谜&#34;会话:part 1part 2

答案 1 :(得分:14)

Swift 3.0解决方案:

//Hide Autolayout Warning
UserDefaults.standard.setValue(false, forKey:"_UIConstraintBasedLayoutLogUnsatisfiable")

答案 2 :(得分:12)

另一种选择是将-_UIConstraintBasedLayoutLogUnsatisfiable NO(注意破折号)暂时置于Arguments Passed On Launch标签下的Product -> Scheme -> Edit Scheme... -> Run -> Arguments菜单中(也可以通过按⇧< / kbd> + + << / kbd>),如下所示:

enter image description here

答案 3 :(得分:5)

任何想知道如何使用AppKit / Cocoa

执行此macOS / osx的人
UserDefaults.standard.set(false, forKey: "NSConstraintBasedLayoutLogUnsatisfiable")
UserDefaults.standard.set(false, forKey: "__NSConstraintBasedLayoutLogUnsatisfiable")

答案 4 :(得分:3)

我试图用lldb来解决这个问题,我找到了一个解决方案:

  1. 为符号创建符号断点 模块UIKit中的UIViewAlertForUnsatisfiableConstraints。
  2. 作为断点操作添加调试器命令“thread return”
  3. 添加第二个调试器命令:“c”
  4. 禁用“自动 评估行动后继续“
  5. 如果您的应用遇到布局问题,则会暂停执行。使用“线程返回”指令,在将警告消息打印到控制台之前,强制打印出错误的UIViewAlertForUnsatisfiableConstraints函数返回。

    使用“c”命令继续执行您的应用程序(注意:“评估操作后自动继续”在这种情况下确实不起作用)

    但是,通过这些自动操作,如果断点连续两次被击中会导致应用程序崩溃,则断点可能会表现得很奇怪。要解决此问题,您可以删除断点操作,并在调试器暂停程序执行时手动输入命令。