UIView高度未调整到UITableView标头中的子视图高度

时间:2015-11-27 23:16:35

标签: ios constraints xcode7

我有一个带标题视图和自定义行的UITableView。标题视图高度未正确调整到其子视图的约束高度。

标题视图容器视图具有以下具有约束高度的子视图:

  • 查看(此高度应计算为188但是为128)
    • 地图:UIImage(身高= 128)
    • 查看:UIView(身高= 60)

enter image description here

标题视图高度应在Map Height + View Height = 128 + 60 = 188时计算,如故事板中所示。但是,在模拟器中运行它会将标题视图调整为128,如下所示:

enter image description here

进一步检查显示标题视图高度为128而不是预期的188:

enter image description here

此外,调试区域显示约束冲突,该冲突显示标题视图高度试图为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.

如何将标题视图高度正确计算到其子视图的高度?

1 个答案:

答案 0 :(得分:1)

为了强制tableViewHeader的高度,我必须使用文本编辑器手动编辑Storyboard文件中的height属性,这样就可以了。

enter image description here

这肯定是Xcode 7.1中的一个错误。