![](/img/trans.png)
[英]Why subview keep sticking to bottom and not adjusting according to parent UIView height
[英]UIView height not adjusting to subview heights in UITableView header
我有一個帶有標題視圖和自定義行的UITableView。 標題視圖的高度未正確調整為其子視圖的約束高度。
標頭視圖容器視圖具有受高度限制的以下子視圖:
頁眉視圖的高度應按照情節提要中所示的“地圖高度+視圖高度= 128 + 60 = 188”進行計算。 但是,在模擬器中運行此命令會將標題視圖壓縮為128,如下所示:
進一步檢查顯示標題視圖的高度為128,而不是預期的188:
此外,“調試”區域顯示了一個約束沖突,該沖突表明標題視圖的高度正試圖變為128,這與其子視圖的高度沖突。 結果,它壓縮了地圖高度:
2015-11-27 16:58:46.415 MyApp[3387:52799] 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)
(
"<NSAutoresizingMaskLayoutConstraint:0x7fcb5acf1270 h=--& v=--& V:[UIView:0x7fcb5c246620(128)]>",
"<NSLayoutConstraint:0x7fcb5c24c440 V:[Stop Details Container]-(0)-| (Names: Stop Details Container:0x7fcb5c24c490, '|':UIView:0x7fcb5c246620 )>",
"<NSLayoutConstraint:0x7fcb5c24c6f0 V:[Map]-(0)-[Stop Details Container] (Names: Stop Details Container:0x7fcb5c24c490, Map:0x7fcb5c24aa10 )>",
"<NSLayoutConstraint:0x7fcb5c24c830 V:|-(0)-[Map] (Names: Map:0x7fcb5c24aa10, '|':UIView:0x7fcb5c246620 )>",
"<NSLayoutConstraint:0x7fcb5c24c880 V:[Map(128)] (Names: Map:0x7fcb5c24aa10 )>",
"<NSLayoutConstraint:0x7fcb5c24c8d0 V:[Stop Details Container(60)] (Names: Stop Details Container:0x7fcb5c24c490 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fcb5c24c880 V:[Map(128)] (Names: Map:0x7fcb5c24aa10 )>
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.
如何使標題視圖的高度正確計算為其子視圖的高度?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.