扩展UicollectionViewCell,以适合嵌套的UicollectionView的宽度
我有一个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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最终,我能够使用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/