因冲突的自动布局限制而感到困惑

时间:2013-12-31 13:59:09

标签: iphone ios7 autolayout autoresizingmask

当我点击tabbar tabitem更改viewcontroller时,我收到了这个崩溃日志:

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) 
(
"<NSAutoresizingMaskLayoutConstraint:0xdb98e30 h=--- v=--- H:[UIWindow:0xc65c530(320)]>",
"<NSAutoresizingMaskLayoutConstraint:0xdbba9a0 h=-&- v=-&- UITransitionView:0xdb43ab0.width == UILayoutContainerView:0xdb42ef0.width>",
"<NSAutoresizingMaskLayoutConstraint:0xc680b80 h=-&- v=-&- UILayoutContainerView:0xdb42ef0.width == UIWindow:0xc65c530.width>",
"<NSAutoresizingMaskLayoutConstraint:0x119352f0 h=-&- v=-&- UIViewControllerWrapperView:0xc68a2c0.width == UITransitionView:0xdb43ab0.width>"
)

 Will attempt to recover by breaking constraint 
<NSAutoresizingMaskLayoutConstraint:0x119352f0 h=-&- v=-&- UIViewControllerWrapperView:0xc68a2c0.width == UITransitionView:0xdb43ab0.width>

 Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

1 个答案:

答案 0 :(得分:1)

首先,您如何应用这些约束?这些冲突消息的最常见原因是添加约束而不确保它们是视图中唯一的约束。你设置了属性

  

translatesAutoresizingMaskIntoConstraints = NO

在尝试设置更多之前?因为您在运行时收到此异常,所以看起来Xcode已经接受了您尝试执行的操作,因此您可能在代码中添加了约束。

您是否在列表中添加了所有这些约束冲突的约束?如果是这样,删除它们并逐个替换它们以找出哪个错误。

如果您在Xcode中使用我们以前所知的Interface Builder进行所有这些操作,请使用新工具检查所有约束并验证您是否未添加冲突的约束。 Xcode可以帮到你。

如果要在代码中添加约束但是您已在IB中创建了视图,那么您可能希望管理IB中的所有约束,或者您希望将xib设置为NOT使用autolayout,以便它不应用冲突的约束用你以后添加的内容。