xcode 带有垂直滚动的 View 内的 UICollectionView 和 ScrollView
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14526963/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UICollectionView and ScrollView inside View with vertical scrolling
提问by Cleyton T.
How can I scroll entire window with UIScrollView on top to display a image gallery, and an UICollectionView to show another items? (See the mockup bellow)
如何在顶部使用 UIScrollView 滚动整个窗口以显示图片库,并使用 UICollectionView 显示其他项目?(见下面的样机)
I tried this structure but only the collection view scrolls and scrollview stays on the top.
我尝试了这种结构,但只有集合视图滚动并且滚动视图停留在顶部。
- View
- UIScrollView
- UICollectionView
- 看法
- 用户界面滚动视图
- 用户界面集合视图
What control should I use to group the scrollview and collectionview to have vertical scrolling on the entire window (and the collection view to grow with it contents)?
我应该使用什么控件来分组滚动视图和集合视图以在整个窗口上垂直滚动(以及集合视图随其内容增长)?
[Mockup] http://img835.imageshack.us/img835/3138/prototyperl.png
[样机] http://img835.imageshack.us/img835/3138/prototyperl.png
采纳答案by Morten Holmgaard
I would just use a UICollectionView and add the UIView as the header for the first section - and it would properly also be the simplest solution.
我只会使用 UICollectionView 并将 UIView 添加为第一部分的标题 - 它也将是最简单的解决方案。
If you wrap the UICollectionView in the ScrollView and resizes the UICollectionView to fit content size you will most likely get poor performance, because all cells will be rendered when the view is shown(Not when cells are visible) - missing the point of reusable cells.
如果您将 UICollectionView 包装在 ScrollView 中并调整 UICollectionView 的大小以适应内容大小,您很可能会获得较差的性能,因为在显示视图时(而不是在单元格可见时)将呈现所有单元格 - 缺少可重用单元格的点。
Override UICollectionViewDataSource delegate method:
覆盖 UICollectionViewDataSource 委托方法:
-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
回答by ader
UIScrollView as the parent with the other two as children
UIScrollView 作为父级,另外两个作为子级
- UIScrollView
- UIView
- UICollectionView
- 用户界面滚动视图
- 界面视图
- 用户界面集合视图