简体   繁体   中英

UICollectionView and ScrollView inside View with vertical scrolling

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)

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

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.

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.

Override UICollectionViewDataSource delegate method:

-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath

UIScrollView as the parent with the other two as children

  • UIScrollView
    • UIView
    • UICollectionView

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM