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

Mar*_*uro 63 xcode ios 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.
Run Code Online (Sandbox Code Playgroud)

小智 168

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

对于Swift 3

 UserDefaults.standard.setValue(false, forKey: "_UIConstraintBasedLayoutLogUnsatisfiable")
Run Code Online (Sandbox Code Playgroud)

Objective-C的

[[NSUserDefaults standardUserDefaults] setValue:@(NO) forKey:@"_UIConstraintBasedLayoutLogUnsatisfiable"];
Run Code Online (Sandbox Code Playgroud)

现在,您只会收到"_UIConstraintBasedLayoutLogUnsatisfiable is OFF"的通知.

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

  • 确切地说 - 我需要暂时禁用错误,以便我可以修复其他内容,然后再回到自动布局噩梦.谢谢你! (18认同)

dan*_*kos 19

另一种选择是暂时将-_UIConstraintBasedLayoutLogUnsatisfiable NO(注意破折号)放入Arguments Passed On Launch菜单,在Product -> Scheme -> Edit Scheme... -> Run -> Arguments选项卡下(您也可以按?+ ?+打开此菜单<),如下所示:

在此处输入图片说明

  • 伟大的。我认为这是删除不需要的日志的最佳解决方案 (2认同)

Sou*_*rma 15

Swift 3.0解决方案:

//Hide Autolayout Warning

UserDefaults.standard.set(false, forKey: "_UIConstraintBasedLayoutLogUnsatisfiable")
Run Code Online (Sandbox Code Playgroud)

  • 为什么用重复解决方案添加新答案,何时可以编辑原始答案。 (3认同)

Cha*_*tas 5

对于任何想知道如何使用AppKit / Cocoa进行macOS / osx的用户

UserDefaults.standard.set(false, forKey: "NSConstraintBasedLayoutLogUnsatisfiable")
UserDefaults.standard.set(false, forKey: "__NSConstraintBasedLayoutLogUnsatisfiable")
Run Code Online (Sandbox Code Playgroud)