UITableViewCell 中的简单 UIStackView 在 IB 中无法正确计算高度

Simple UIStackView in UITableViewCell not working out height properly in IB

我的布局如下:

Table View (dynamic prototypes, row: automatic height and estimate)
  Table View Cell (row height: default)
    Content View
      Stack View (axis: horizontal, alignment: center, distribution: fill)
        Image View (height: 70, width: 70)
        Label

UITableView 对其父视图有所有 4 个约束(顶部、底部、前导和尾随)。相对于它的超级视图,UIStackView 也是如此。

问题是行高不是在界面生成器内部计算的,实际上它指向以下冲突约束:

bottom = Stack View.bottom
height = 70
Stack View.top = top
centerY = Image View.centerY

我觉得这个布局超级简单,我很困惑为什么它不起作用。

如果您当前的故事板看起来像前两张图片:

那么问题就出在你在 70 的图像视图上设置了高度限制,但是 table 视图单元格的默认高度仅为 44 .这没有为自动布局留下足够的空间来满足所有约束。

如果您将行高(在“大小检查器”窗格中)更改为 71,冲突约束就会消失: