扩展UicollectionViewCell,以适合嵌套的UicollectionView的宽度

发布于 2025-01-24 12:12:38 字数 697 浏览 0 评论 0原文

我有一个uicollectionviewcell,我想在敲击时扩展。该单元只是一个标题,然后扩展到较小的UicollectionView。外部UICollectionViewCell是通过AutoLayout(在UistackView中)布置的(尽管我没有结婚,如果这是一个问题)。

例如

[ -------NFL------- ] -> (This is an unexpanded cell)
| -------NBA------- | -> (This is an expanded cell)
| [Nets Vs. Celtics]| -> (These are cells of a collection view that's inside the expanded cell)
| [Hawks Vs. Heat]  | 

,如您所见,如果您点击标头,它将扩展并显示该联盟中当前的所有游戏。

问题在于UicollectionViewCell需要指定的维度。我知道宽度应该是什么(只是安全区域布局宽度),但我似乎无法理解我希望高度灵活。我认为这是一个问题的原因是,由于我将一个CollectionView嵌套在另一个集合中,因此Outer CollectionView无法确定其内在的内容大小。

这里有什么想法 /解决方法吗?我使用联赛收集视图(外部收集视图)的原因是因为我不一定事先知道联盟会出现哪些联赛(即,只有在有活动的游戏时才出现。)

I have a UICollectionViewCell that I want to expand when tapped. The cell is just a header that then expands into a smaller UICollectionView. The outer UICollectionViewCell is laid out via AutoLayout (in a UIStackView, although I'm not married to that idea if it's a problem).

E.g.

[ -------NFL------- ] -> (This is an unexpanded cell)
| -------NBA------- | -> (This is an expanded cell)
| [Nets Vs. Celtics]| -> (These are cells of a collection view that's inside the expanded cell)
| [Hawks Vs. Heat]  | 

So as you can see, if you tap a header, it expands and shows all of the current games in that given league.

The problem is that a UICollectionViewCell needs specified dimensions. I know what the width should be (just the safe area layout width), but I can't seem to get it to understand that I want the height to be flexible. I think the reason that this is a problem is that since I'm nesting one collectionview inside of another, the outer collectionview can't determine its intrinsic content size.

Any ideas / workarounds here? The reason that I'm using a collection view for the leagues (the outer collection view) is because I don't necessarily know beforehand which leagues will appear (i.e. they'll only appear if there are active games.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧夏天 2025-01-31 12:12:38

最终,我能够使用UicollectionLayoutlistConfiguration创建多截面集合视图来实现这一目标。 Donmag的答案指向了正确的方向,但是对于分步实施,我遵循了本指南:

https://swiftsenpai.com/development/collectionview-expandable-list-part1/

I was eventually able to achieve this by creating a multi-section collection view using UICollectionLayoutListConfiguration. DonMag's answer pointed me in the right direction, but for step-by-step implementation, I followed this guide:

https://swiftsenpai.com/development/collectionview-expandable-list-part1/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文