2012-08-11 84 views
3

我使用Xcode 4.4並在界面構建器中創建我的視圖。當我運行我的應用程序時,我始終得到以下約束錯誤。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. 

關於如何解決這個問題的任何建議?

感謝

回答

6

每個視圖你打算上制約做到這一點:

[view setTranslatesAutoresizingMaskIntoConstraints:NO]; 

這將在日誌中擺脫了「NSAutoresizingMaskLayoutConstraint」部分。

2

還有一種方法可以在不編寫代碼的情況下解決這個問題。

在故事板中,選擇您的超級視圖。在屬性檢查器中,取消選中「Autoresize Subviews」複選框,如下所示。

Screenshot of Xcode 5

這將增加autoresizesSubviews="NO"到故事板的XML文件。在我的情況中,XML已經包含translatesAutoresizingMaskIntoConstraints="NO",但是,這並沒有阻止自動佈局創建NSAutoresizingMaskLayoutConstraint

注意:也許我的回答僅適用於Xcode 5,因爲我無法檢查Xcode 4.4是否已經有了這個複選框。但是由於Google在搜索NSAutoresizingMaskLayoutConstraint時仍然會出現這個問題,因此可能會讓某人受益。