带内容视图的UIScrollView - Autolayout问题

时间:2015-09-05 17:06:17

标签: objective-c uiscrollview autolayout nsautolayout

我在滚动视图中添加对子视图的约束时遇到问题。我遍历一个UIViews数组,并且我的数组中的最终对象存在冲突。约束中断。以下是重现此问题的code

有人可以在这里指导我吗?

控制台日志:

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.

1 个答案:

答案 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']-|;