本文介绍了禁用调试控制台输出自动布局约束错误信息以x code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种办法(临时)禁用自动布局错误/警告消息:

 无法同时满足约束条件。
    大概在以下列表中的约束条件中的至少一个是一个你不想要的。试试这个:(1)看一下每个约束和揣摩,你不要指望; (2)找到code,它增加了不必要的约束或限制并修复它。 (注:如果你看到你不明白NSAutoresizingMaskLayoutConstraints,请参阅文档UIView的财产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 gt;中
)将试图打破约束恢复
&所述; NSLayoutConstraint:0x170098420 H:[UIView的:0x15c62c100(2)]≥做一个象征性的断点UIViewAlertForUnsatisfiableConstraints赶上这在调试器。
在UIView的的UIConstraintBasedLayoutDebugging类别中列出的方法<的UIKit / UIView.h>也可能是有帮助的。


解决方案

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

斯威夫特

  NSUserDefaults.standardUserDefaults()的setValue(假,forKey:_UIConstraintBasedLayoutLogUnsatisfiable)。

目标-C

  [NSUserDefaults的standardUserDefaults]的setValue:@(NO)forKey:@_ UIConstraintBasedLayoutLogUnsatisfiable];

现在你只能得到通知_UIConstraintBasedLayoutLogUnsatisfiable为OFF。

任何人阅读本强制性提醒:这应该是最后的手段,对调试技巧和解决问题的约束WWDC看到的自动布局之谜的会议:的和部分2

Is there a way to (temporarily) disable autolayout error/warning messages:

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.
解决方案

Did some decompiling and there's actually a way:

Swift

NSUserDefaults.standardUserDefaults().setValue(false, forKey: "_UIConstraintBasedLayoutLogUnsatisfiable")

Objective-C

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

Now you'll only get notified that "_UIConstraintBasedLayoutLogUnsatisfiable is OFF".

Obligatory reminder for anyone reading this: this should be last resort, for tips on debugging and fixing constraint issues see WWDC's "Mysteries of Auto Layout" sessions: part 1 and part 2.

这篇关于禁用调试控制台输出自动布局约束错误信息以x code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 12:15