gpt4 book ai didi

ios - 如何让 UICollectionView 在不离开屏幕的情况下使用自动布局填充其包含的 ScrollView 的宽度?

转载 作者:行者123 更新时间:2023-11-29 13:10:34 24 4
gpt4 key购买 nike

我的 View 层次结构看起来像这样:

- View
- Scroll View
- Collection View

我正在使用自动布局。问题是,当我指定 Collection View 应占据父 View 的整个宽度时,它最终实际上占据了其中包含的元素的整个宽度。即,如果此 Collection View 中有 1000 个元素,并且每个元素的宽度为 10 像素,则 Collection View 将为 10000 像素。它似乎忽略了我的约束。

我使用的 VFL 看起来有点像这样:

ScrollView

H:|[scroll]|
V:|[scroll]|

Collection View

H:|[collection]|
V:|[collection]|

所有 View 都设置为不将自动调整大小掩码转换为约束。

最佳答案

when I specify that the collection view should take the full width of the superview, it ends up actually taking the full width of the elements contained within it.

ScrollView 的全部意义在于它允许显示比 ScrollView 本身更大的 View 。因此,将集合限制为 ScrollView 是没有意义的—— ScrollView 的 subview 可以随心所欲地变大。如果您想限制 Collection View 的大小,只需将其宽度设置为您喜欢的任何宽度即可。

关于ios - 如何让 UICollectionView 在不离开屏幕的情况下使用自动布局填充其包含的 ScrollView 的宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17496102/

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