Xcode 4.4约束错误

时间:2012-08-11 20:54:36

标签: xcode4 constraints

我正在使用Xcode 4.4并在界面构建器中创建我的视图。当我运行我的应用程序时,我始终遇到以下约束错误。

Unable to simultaneously satisfy constraints:
(
    "<NSAutoresizingMaskLayoutConstraint:0x104486db0 h=-&- v=-&- V:[NSView:0x106a33090]-(0)-|   (Names: '|':NSClipView:0x106a0cef0 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x104486e10 h=-&- v=-&- V:|-(15)-[NSView:0x106a33090]   (Names: '|':NSClipView:0x106a0cef0 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x1002da350 h=--& v=--& V:[NSClipView:0x106a0cef0(672)]>",
    "<NSLayoutConstraint:0x106a11ba0 V:[NSView:0x1044eb990]-(657)-|   (Names: '|':NSView:0x106a33090 )>",
    "<NSLayoutConstraint:0x1044d68d0 V:|-(270)-[NSView:0x1044eb990]   (Names: '|':NSView:0x106a33090 )>",
    "<NSLayoutConstraint:0x100271040 V:[NSView:0x1044eb990(245)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x100271040 V:[NSView:0x1044eb990(245)]>

Set the NSUserDefault NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints 
to YES to have -[NSWindow visualizeConstraints:] automatically called when this happens.
And/or, break on objc_exception_throw to catch this in the debugger.

有关如何解决此问题的任何建议?

由于

2 个答案:

答案 0 :(得分:6)

对于您打算约束的每个视图,请执行以下操作:

[view setTranslatesAutoresizingMaskIntoConstraints:NO];

这将消除日志中的“NSAutoresizingMaskLayoutConstraint”部分。

答案 1 :(得分:2)

还有一种方法可以在不编写代码的情况下解决这个问题。

在故事板中,选择您的超级视图。在“属性”检查器中,取消选中“自动调整子视图”复选框,如下所示。

Screenshot of Xcode 5

这会将autoresizesSubviews="NO"添加到storyboard XML文件中。就我而言,XML已经包含translatesAutoresizingMaskIntoConstraints="NO",但是,这并没有阻止autolayout创建NSAutoresizingMaskLayoutConstraint

注意:也许我的回答仅适用于 Xcode 5 ,因为我无法检查Xcode 4.4是否已经拥有此复选框。但是,由于Google在搜索NSAutoresizingMaskLayoutConstraint时仍然提出了这个问题,因此可能会对某人有所帮助。