设置约束时,CollectionViews变得怪异 [英] Collectionviews move weird when setting constraints
问题描述
我的应用程序中有三个 collectionViews
。现在,我完成了所需的一切。我现在几天遇到的唯一问题是约束。我不知道如何用语言解释它,所以我在问题上加了两张图片,希望它是可以理解的。
I got three collectionViews
in my application. Now I finished it as far as I wanted it to complete. The only problem which I have for several days now are the constraints. I don't know how to explain it in words so I added two pictures of the problem to the question I hope it's understandable.
我目前拥有什么:
我想要什么:
推荐答案
基于您的屏幕截图,它看起来像集合视图当超级视图(屏幕尺寸)改变时,按住白点列将扩大其宽度。
Based on your screenshots, it looks like the collection view holding the column of white dots expands its width when the superview (the screen size) changes.
看起来您正在使用流布局 ...当视图变宽时,每行有足够的空间容纳2个单元格。
It also looks like you are using Flow Layout... when the view gets wider there is enough room for 2 cells on each row.
您应该可以通过以下任一方法来解决此问题:
You should be able to fix that by either:
- 限制该集合视图的宽度,以便't扩展,或者
- 使用自定义的收藏夹视图布局
我建议尝试首先是宽度约束-查看是否可以使布局看起来像您想要的样子。
I'd suggest trying a width constraint first - see if you can get the layout to look the way you want.
作为补充说明...使用集合视图可能不是最好的方法您正在尝试做的事情。 UIStackView
可能是一个更好的选择(尽管我不知道该界面还会做什么,所以也许不是)。
As a side note... using collection views may not be the best approach for what you're trying to do. UIStackView
might be a better option (although, I don't know what else the interface will be doing, so maybe not).
这篇关于设置约束时,CollectionViews变得怪异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!