简体   繁体   English

具有两个表视图和标签的Stackview导致重叠

[英]Stackview with two table views and labels causes overlap

I've been trying to build the following view that I already built in an Android app: 我一直在尝试构建已经在Android应用程序中构建的以下视图:

Android布局

I used a stack view to layout the views vertically. 我使用了堆栈视图来垂直排列视图。 There is a label, followed by first table view, then another label, then another table view(Android configuration is the same): 有一个标签,然后是第一个表格视图,然后是另一个标签,然后是另一个表格视图(Android配置相同):

iOS布局

What I would expect is to have the first table view stretch to accomodate the 3 items inside, the label after it to follow, and so on without constraining heights. 我希望在不限制高度的情况下,使第一个表格视图能够容纳其中的3个项目,跟随其后的标签等等。

This is how the autolayout looks like: 这是自动布局的样子:

自动布局

And these are the constraints I set up: 这些是我设置的约束:

约束条件

How can I achieve the same view like in Android? 如何获得与Android中相同的视图?

The problem is that views based on UIScrollView (all table views and collection views are) don't have an intrinsic size to return to the Stack View; 问题是基于UIScrollView的视图(所有表视图和集合视图都是)没有返回到堆栈视图的固有大小; they could theoretically be of infinite size. 从理论上讲,它们可以是无穷大的。 The correct way to solve this is not to put them in a stack view, but add them as constrained sub-views with the following constraints: 解决此问题的正确方法不是将它们放在堆栈视图中,而是将它们添加为具有以下约束的受约束子视图:

  • Top table view is constrained equal to the top, leading, and trailing edges of its superview. 顶表视图被约束为等于其超级视图的顶部,顶部和底部。
  • Bottom table view is constrained equal to the bottom, leading, and trailing edges of its superview. 底表视图的约束等于其超级视图的底边,前边和后边。
  • Top table view's bottom anchor is equal to the top anchor of the bottom table view. 顶视图的底部锚点等于底视图的顶部锚点。
  • Top and bottom table views are constrained to have equal heights. 顶视图和底视图的高度被限制为相等。

That will force the table views to each use half of the available screen space, while remaining flexible for different screen sizes. 这将迫使表格视图各自使用可用屏幕空间的一半,同时保持灵活性以适应不同的屏幕尺寸。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM