2015-09-05 99 views
0

我在滾動視圖中的子視圖上添加約束時遇到問題。我遍歷UIViews數組,並且在數組中的最後一個對象上存在衝突。約束中斷。這裏是code重現此問題。帶內容視圖的UIScrollView - Autolayout問題

有人可以在這裏指導我嗎?

控制檯登錄:

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:0x7f8195006be0 UIScrollView:0x7f8195006320.height == UIView:0x7f8195005be0.height>", 
    "<NSLayoutConstraint:0x7f8195019760 V:|-(0)-[UIScrollView:0x7f8195006320] (Names: '|':UIView:0x7f81950180d0)>", 
    "<NSLayoutConstraint:0x7f8195019850 V:[UIScrollView:0x7f8195006320]-(0)-[_UILayoutGuide:0x7f8195018fc0]>", 
    "<_UILayoutSupportConstraint:0x7f8195004b80 V:[_UILayoutGuide:0x7f8195018fc0(0)]>", 
    "<_UILayoutSupportConstraint:0x7f81950008c0 _UILayoutGuide:0x7f8195018fc0.bottom == UIView:0x7f81950180d0.bottom>", 
    "<NSLayoutConstraint:0x7f8192e3c540 V:[UIButton:0x7f819500dc40'Test Btn 0'(30)]>", 
    "<NSLayoutConstraint:0x7f8192e3d040 V:|-(130)-[UIButton:0x7f819500dc40'Test Btn 0'] (Names: '|':UIView:0x7f8195005be0)>", 
    "<NSLayoutConstraint:0x7f8192e3d8f0 V:[UIButton:0x7f819501a7d0'Test Btn 1'(30)]>", 
    "<NSLayoutConstraint:0x7f8192e3e270 V:[UIButton:0x7f819500dc40'Test Btn 0']-(130)-[UIButton:0x7f819501a7d0'Test Btn 1']>", 
    "<NSLayoutConstraint:0x7f8192e3e4c0 V:[UIButton:0x7f819501abf0'Test Btn 2'(30)]>", 
    "<NSLayoutConstraint:0x7f8192e3ec10 V:[UIButton:0x7f819501a7d0'Test Btn 1']-(130)-[UIButton:0x7f819501abf0'Test Btn 2']>", 
    "<NSLayoutConstraint:0x7f8192e3f040 V:[UIButton:0x7f819501ae10'Test Btn 3'(30)]>", 
    "<NSLayoutConstraint:0x7f8192e3f5d0 V:[UIButton:0x7f819501abf0'Test Btn 2']-(130)-[UIButton:0x7f819501ae10'Test Btn 3']>", 
    "<NSLayoutConstraint:0x7f8192e3faa0 V:[UIButton:0x7f819501b030'Test Btn 4'(30)]>", 
    "<NSLayoutConstraint:0x7f8192e40040 V:[UIButton:0x7f819501ae10'Test Btn 3']-(130)-[UIButton:0x7f819501b030'Test Btn 4']>", 
    "<NSLayoutConstraint:0x7f8192e40380 V:[UIButton:0x7f819501b250'Test Btn 5'(30)]>", 
    "<NSLayoutConstraint:0x7f8192e40d50 V:[UIButton:0x7f819501b030'Test Btn 4']-(130)-[UIButton:0x7f819501b250'Test Btn 5']>", 
    "<NSLayoutConstraint:0x7f8192e410b0 V:[UIButton:0x7f819501b470'Test Btn 6'(30)]>", 
    "<NSLayoutConstraint:0x7f8192e41720 V:[UIButton:0x7f819501b250'Test Btn 5']-(130)-[UIButton:0x7f819501b470'Test Btn 6']>", 
    "<NSLayoutConstraint:0x7f8192e41aa0 V:[UIButton:0x7f819501b690'Test Btn 7'(30)]>", 
    "<NSLayoutConstraint:0x7f8192e3f500 V:[UIButton:0x7f819501b470'Test Btn 6']-(130)-[UIButton:0x7f819501b690'Test Btn 7']>", 
    "<NSLayoutConstraint:0x7f8192e42410 V:[UIButton:0x7f819501b8b0'Test Btn 8'(30)]>", 
    "<NSLayoutConstraint:0x7f8192e3feb0 V:[UIButton:0x7f819501b690'Test Btn 7']-(130)-[UIButton:0x7f819501b8b0'Test Btn 8']>", 
    "<NSLayoutConstraint:0x7f8192e42d70 V:[UIButton:0x7f819501bad0'Test Btn 9'(30)]>", 
    "<NSLayoutConstraint:0x7f8192e3b030 V:[UIButton:0x7f819501b8b0'Test Btn 8']-(130)-[UIButton:0x7f819501bad0'Test Btn 9']>", 
    "<NSLayoutConstraint:0x7f8192e32bd0 UIButton:0x7f819501bad0'Test Btn 9'.bottom == UIView:0x7f8195005be0.bottom + 100>", 
    "<NSLayoutConstraint:0x7f8192e442b0 'UIView-Encapsulated-Layout-Height' V:[UIView:0x7f81950180d0(667)]>" 
) 

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7f8192e3b030 V:[UIButton:0x7f819501b8b0'Test Btn 8']-(130)-[UIButton:0x7f819501bad0'Test Btn 9']> 

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. 
+0

請添加控制檯輸出,告訴您哪些約束被破壞以及爲什麼。 – johnpatrickmorgan

+0

我添加了一個測試代碼來重現問題 –

回答

0

我想這裏的問題是,你尚未初始化terminalUIElements陣列。我無法在您的代碼中找到它。

<NSLayoutConstraint:0x7f8192e3b030 V:[UIButton:0x7f819501b8b0'Test Btn 8']-(130)-[UIButton:0x7f819501bad0'Test Btn 9']> 

嘗試添加到您的約束。

V:[UIButton:0x7f819501b8b0'Test Btn 8']-(130)-[UIButton:0x7f819501bad0'Test Btn 9']-|; 
+0

更新了代碼。 –

+0

確保您擁有所有視圖的所有四個方向。在使用自動佈局時,在滾動視圖內部,通過子視圖約束的幫助來計算內容大小。您無需提供內容大小。最後的子視圖也應定義距離超視圖底部的距離。因此,它涵蓋了所有四個方面的自動佈局約束。 你也不需要把圓括號。五:| -O - [圖] -O - |。這也會起作用。 –