在日志中查找自动布局约束错误

时间:2015-07-20 03:49:46

标签: ios xcode autolayout interface-builder

我的日志中出现了一堆自动布局约束错误,尽管我的故事板中没有。我无法理解其中大部分内容,尤其是查找抛出错误的特定视图和文本字段:

2015-07-19 20:39:28.625 Daily[42447:417537] 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:0x7fd8a3e309e0 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7fd8a3dc4ea0(375)]>",
"<NSLayoutConstraint:0x7fd8a3dcc3f0 UIView:0x7fd8a3f416c0.leading == UIView:0x7fd8a3dc4ea0.leadingMargin>",
"<NSLayoutConstraint:0x7fd8a3dcc4e0 UIView:0x7fd8a3dc4ea0.centerX == UIView:0x7fd8a3f416c0.centerX>",
"<NSLayoutConstraint:0x7fd8a3dcc670 V:[UIView:0x7fd8a3f416c0(81)]>",
"<NSLayoutConstraint:0x7fd8a3dcc6c0 UIView:0x7fd8a3f416c0.width == 4.54321*UIView:0x7fd8a3f416c0.height>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7fd8a3dcc6c0 UIView:0x7fd8a3f416c0.width == 4.54321*UIView:0x7fd8a3f416c0.height>
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.

2015-07-19 20:39:28.627 Daily[42447:417537] 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:0x7fd8a3e309e0 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7fd8a3dc4ea0(375)]>",
"<NSLayoutConstraint:0x7fd8a3dcbf20 V:[UIView:0x7fd8a3dc4a50]-(76)-[UIView:0x7fd8a3dcb8b0]>",
"<NSLayoutConstraint:0x7fd8a3dcbfc0 V:[_UILayoutGuide:0x7fd8a3dc4fb0]-(322)-[UIView:0x7fd8a3dcb8b0]>",
"<NSLayoutConstraint:0x7fd8a3dcc010 UIView:0x7fd8a3dc4ea0.width == 3.25203*UIView:0x7fd8a3dc4a50.height>",
"<NSLayoutConstraint:0x7fd8a3dcc100 V:[UIView:0x7fd8a3dcc150]-(34)-[UIView:0x7fd8a3dc4a50]>",
"<NSLayoutConstraint:0x7fd8a3dcc5d0 V:[_UILayoutGuide:0x7fd8a3dc4fb0]-(31)-[UIView:0x7fd8a3dcc150]>",
"<NSLayoutConstraint:0x7fd8a3dcdec0 H:[UIView:0x7fd8a3dcc150(368)]>",
"<NSLayoutConstraint:0x7fd8a3dcdf10 UIView:0x7fd8a3dcc150.width == 6.34483*UIView:0x7fd8a3dcc150.height>"
)

Will attempt to recover by breaking constraint 

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.
2015-07-19 20:39:28.628 Daily[42447:417537] 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:0x7fd8a3e309e0 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7fd8a3dc4ea0(375)]>",
"<NSLayoutConstraint:0x7fd8a3dcbed0 UIView:0x7fd8a3dcb8b0.trailing == UIView:0x7fd8a3dc4ea0.trailingMargin>",
"<NSLayoutConstraint:0x7fd8a3dcbf70 UIView:0x7fd8a3dcb8b0.leading == UIView:0x7fd8a3dc4ea0.leadingMargin>",
"<NSLayoutConstraint:0x7fd8a3dccf80 H:[UIView:0x7fd8a3dcb8b0(368)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7fd8a3dccf80 H:[UIView:0x7fd8a3dcb8b0(368)]>

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.
2015-07-19 20:39:28.644 Daily[42447:417537] 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:0x7fd8a3e309e0 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7fd8a3dc4ea0(375)]>",
"<NSLayoutConstraint:0x7fd8a3dcc3f0 UIView:0x7fd8a3f416c0.leading == UIView:0x7fd8a3dc4ea0.leadingMargin>",
"<NSLayoutConstraint:0x7fd8a3dcc4e0 UIView:0x7fd8a3dc4ea0.centerX == UIView:0x7fd8a3f416c0.centerX>",
"<NSLayoutConstraint:0x7fd8a3dcc620 H:[UIView:0x7fd8a3f416c0(368)]>"
)

Will attempt to recover by breaking constraint 

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.

2 个答案:

答案 0 :(得分:2)

您正在为视图添加错误的约束。如果添加centerX约束,则无需添加前导空间约束,它将与约束冲突。将约束添加为centerX,height,width和&amp;根据需要给出Y位置。

答案 1 :(得分:1)

你的方法很明显。但是,大多数情况下我想通过禁用自动布局和类来开发应用程序。您需要在界面构建器中设置调整大小边距。如果你不清楚我的解决方案,请告诉我,我会清楚地解释:) :)