2015-09-05 80 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 - |。这也会起作用。 –