使用“可读内容指南”和灵活的缩略图,高度不明确

时间:2019-01-25 13:00:22

标签: ios autolayout

我有一个视频缩略图(一个bind status A @git add -A ),我希望它具有灵活的尺寸,而不是固定的宽度和高度(以前是固定的)。它必须具有灵活性,因为我要在缩略图和单元格内容视图的readableContentGuide属性的布局锚点之间添加前导和尾随约束。

因此,我为缩略图高度锚定了一个比率,以使用其宽度定义高度:

@

缩略图的位置和大小正确,但是其余内容的高度错误:

Thumbnail with ambiguous height

Constraints of the Thumbnail with ambiguous height

Constraints of the content with ambiguous height

其余的内容限制是这样设置的:

UIImageView

如果我对缩略图强加一个固定的 height 值,那么一切都会顺利进行:

Thumbnail with no ambiguous height

Constraints with no ambiguous height

如何避免为Thumbnail设置固定的高度并获得清晰的布局?

更新:

演示项目:https://github.com/ricardopereira/ThumbnailLayoutIssue

1 个答案:

答案 0 :(得分:1)

您应该始终将约束应用于单元格的|而不是单元格本身。

在此之后,在您的示例中,您应将contentView替换为layoutMarginsGuide

您还应该将contentView.layoutMarginsGuide的{​​{1}}设置为stackView