UITableView 可以在里面滚动 UICollectionView 吗?

Can UITableView scroll with UICollectionView inside it?(UITableView 可以在里面滚动 UICollectionView 吗?)
本文介绍了UITableView 可以在里面滚动 UICollectionView 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有下面的结构...

我将两个集合视图包装到 tableview 中

I wrap two of collection views into tableview

一个在tableview header(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-商店标头

      这篇关于UITableView 可以在里面滚动 UICollectionView 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

      本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Cancel current UIScrollView touch(取消当前 UIScrollView 触摸)
How to make a screenshot of all the content of a Scrollview?(如何截取 Scrollview 的所有内容?)
Swift iOS Set scrollView constraint below navigation bar programmatically(Swift iOS以编程方式在导航栏下方设置滚动视图约束)
UILabel sizeToFit method not working properly(UILabel sizeToFit 方法无法正常工作)
UIScrollView lazy loading of images to reduce memory usage and avoid crash(UIScrollView 延迟加载图片以减少内存使用并避免崩溃)
Infinite horizontal scrolling UIScrollView(无限水平滚动 UIScrollView)