很多时候我们会遇到约束冲突的问题、但是因为苹果只会在log中提示冲突、且这些冲突很难去理解、所以遇到冲突、也很难发现到底是哪里出了问题、但是苹果还是提供了方法、去debug的。
我们来看冲突的log:
2015-08-26 14:29:32.870 Auto Layout Cookbook[10208:1918826] 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:0x7b58bac0 'Label Leading' UILabel:0x7b58b040'Name'.leading == UIView:0x7b590790.leadingMargin>",
"<NSLayoutConstraint:0x7b56d020 'Label Width' H:[UILabel:0x7b58b040'Name'(>=400)]>",
"<NSLayoutConstraint:0x7b58baf0 'Space Between Controls' H:[UILabel:0x7b58b040'Name']-(NSSpace(8))-[UITextField:0x7b589490]>",
"<NSLayoutConstraint:0x7b51cb10 'Text Field Trailing' UITextField:0x7b589490.trailing == UIView:0x7b590790.trailingMargin>",
"<NSLayoutConstraint:0x7b0758c0 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7b590790(320)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7b56d020 'Label Width' H:[UILabel:0x7b58b040'Name'(>=400)]>
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.
里面写了
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
这就意味着、我们可以通过symbolic breakpoint 来捕捉冲突、如何来设定呢?平时管理断点的地方、点击加号、addMake a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.然后在symbol内容填上UIViewAlertForUnsatisfiableConstraints、如果出现冲突、系统会自动停留在断点处、还是蛮好用的。
更多断点知识、可以参考cocoa的文章只会左键断点?是时候试试这样那样断点了