UITableView可以在里面滚动UICollectionView吗? [英] Can UITableView scroll with UICollectionView inside it?
问题描述
我有以下结构......
I have the structures below...
我将两个集合视图包装到tableview中
I wrap two of collection views into tableview
一个在tableview标题(Collection1)中,另一个在tableview第一行(Collection2)中。
One is in tableview header(Collection1), another is in tableview 1st row(Collection2).
所有功能都很好(两个集合视图)。
All the functions are good (Both collection view).
只是...
当我在Collection2中向上滚动时,Collection1将不会向上滚动,因为我只滚动collectionViews而不是tableview。
When I scroll up in Collection2, Collection1 will Not scroll up together, because I'm only scrolling the collectionViews not the tableview.
它只在一起滚动我在Collection1中滚动。
It only scroll together when I scroll in Collection1.
是否可以像使用商店的索引轮播标题一样向用户滚动标题视图?
Is it possible to make the header view scroll with user just like app store's index carousel header?
或者我只是去了错误的地方,我应该用其他方式来接近。
Or I just went to the wrong place, I should use other ways to approach.
推荐答案
解决方案
-
当您将CollectionView1保存为TableViewHeader时,CollectionView1在到达顶部后将始终位于TableView的顶部。如果您希望Collection1和Collection2一起向上滚动,则需要将CollectionView1保存在单元格中,而不是标题。
Solution
When you keep CollectionView1 as a TableViewHeader, CollectionView1 will always on the top of TableView after it reaches top. If you want Collection1 and Collection2 scroll up together, you need to keep CollectionView1 in a cell, not a header.
确保CollectionView2内容高度小于或等于TableViewCell的高度。当我在App Store上查看时,他们总是使SubCollectionView内容高度等于TableViewCell的高度(如果他们使用TableView)。
Make sure CollectionView2 content height smaller or equal to TableViewCell's height. As I checked on App Store, they always make SubCollectionView content height equal to TableViewCell's height (If they use TableView).
有关详细信息,您可以查看我的示例项目
For more detail, you can take a look at my sample project
https://github.com/trungducc/stackoverflow/tree/app-store-header
这篇关于UITableView可以在里面滚动UICollectionView吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!