我在滾動視圖中的子視圖上添加約束時遇到問題。我遍歷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.
請添加控制檯輸出,告訴您哪些約束被破壞以及爲什麼。 – johnpatrickmorgan
我添加了一個測試代碼來重現問題 –