gpt4 book ai didi

ios - 如何在自动布局中为表格 View 提供灵活的高度?

转载 作者:行者123 更新时间:2023-11-29 00:29:41 27 4
gpt4 key购买 nike

我想要一个场景,顶部有一个垂直堆栈 View ,下面有一个表格 View 。场景如下:

View
Stack view
Table view

我希望自动布局:

Let the stack view consume as much vertical space it needs to. The rest of the vertical space goes to the table view.

我使用这些布局约束:

stackView.leading == superview.leading
stackView.trailing == superview.trailing
stackView.top == topLayoutGuide.bottom
tableView.top == stackView.bottom
tableView.leading == superview.leading
tableView.trailing == superview.trailing
tableView.bottom == bottomLayoutGuide.top

但是自动布局提示:

  • Table View: Need constraints for Y position or height.
  • Stack View: Need constraints for Y position or height.

为了解决这个问题,我尝试增加堆栈 View 的垂直内容压缩阻力优先级:

Stack View Content Compression Resistance Priority:
Horizontal: 750
Vertical: 751

Table View Content Compression Resistance Priority:
Horizontal: 750
Vertical: 750

但运气不好,自动布局给出了同样的错误。

我在这里缺少什么?

最佳答案

是的,你没看错。但我想指出,具有动态内容的 View (如堆栈 View 和表格 View )在界面构建器中没有有效的固有内容大小。

So, it seems like since stack views do not have an intrinsic size, we need to put some elements with an intrinsic size in stack views in order for auto-layout to infer a size for the stack views and layout the content unambiguously.

因此,与其添加一些 View 只是为了避免自动布局警告,我们应该在界面构建器中使用Intrinsic Size Placeholder

enter image description here

关于ios - 如何在自动布局中为表格 View 提供灵活的高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42211369/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com