[英]No Constraints found in viewDidLayoutSubviews - AutoLayout
[英]iOS autolayout: set constraints in viewDidLayoutSubviews?
我有一個xib view controller
。 xib包含所有無約束的子視圖,我需要手動添加這些約束。 當我在viewDidLoad
編寫代碼時,一切都正確。 但是我需要獲得一個size參數,該參數僅在viewDidLayoutSubviews
可用。 當我嘗試在viewDidLayoutSubviews
調用代碼時,出現以下錯誤:
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.
(
"<NSLayoutConstraint:0x79edebb0 V:|-(50)-[UILabel:0x79f11bf0'You haven't imported any ...'] (Names: '|':UIView:0x79f11940 )>",
"<NSLayoutConstraint:0x79e4b190 V:|-(49)-[UILabel:0x79f11bf0'You haven't imported any ...'] (Names: '|':UIView:0x79f11940 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x79edebb0 V:|-(50)-[UILabel:0x79f11bf0'You haven't imported any ...'] (Names: '|':UIView:0x79f11940 )>
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.
約束很簡單:所有視圖都放置在一列中,固定寬度,固定高度,最頂層視圖與超級視圖頂部邊框之間的距離,相鄰視圖之間的距離,最后所有視圖都捕捉到超級視圖的水平中心。
更新
我找到了問題的原因,但我不知道為什么它不起作用。
問題是最高的約束值基於視圖的邊界 。 此bounds
結構內的高度值“跳” 1(因為多次調用viewDidLayoutSubviews
)。 但是,為什么它會引起約束問題呢?
它說UILabel中的1個具有約束,這會破壞布局。 2個選擇
警告或錯誤輸出。
基本上是由於您添加了不必要的約束。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.