【问题标题】:UIView height not adjusting to subview heights in UITableView headerUIView 高度未调整到 UITableView 标头中的子视图高度
【发布时间】:2015-11-28 12:06:00
【问题描述】:

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

标题视图容器视图具有以下高度受限的子视图:

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

标题视图高度应按地图高度 + 视图高度 = 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.

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

【问题讨论】:

    标签: ios constraints xcode7


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-10
      • 1970-01-01
      相关资源
      最近更新 更多