简体   繁体   中英

UICollectionView layout for each section

I need to set one of my UICollectionView sections to scroll horizontally, where the rest of the UICollectionView scrolls vertically.

For example: SECTION 1 below should scroll left to right, where the entire UICollectionView scrolls up and down.

|               |   ^
| [ SECTION 0 ] |    
|               |   |
| [   <-->    ] |   |
| [ SECTION 1 ] |   |
| [   <-->    ] |   |
|               |   |
| [ SECTION 2 ] |
|               |   ˅

You cannot nest a new UICollectionView inside of a UICollectionViewCell , so that's out of the question. I also do not want to use a UITableView AND a UICollectionView since I need most of the other sections to be grid layouts.

Any thoughts on how to achieve this?

Take the Tableview which will scroll vertically then in UITablviewCell take UIView (this is done for making non conflicting delegates of collectionview and tableview),With UIView take UICollectionview and make it scroll horizontally .Thus you can achieve this easily.

UITableView->UITbaleviewCell->In Tableviewcell a UIView->then UICollectionview->UICollectionviewCell

This is easier than it sounds (obviously) but there are two ways to do this.

  1. Forget Section 1, instead make that content the Section Header which will contain a UIScrollView that will scroll horizontally. Then add your content there and set the contentSize for that scrollview to the size of the content and you're done. Set tapGestureRecognizers for any items that need to respond within the scrollview.

  2. Make Section 1 a single cell that contains a UIScrollView just like version 1 above.

This is a nice display, I did this recently in a proof of concept that has since been trashed or I'd be able to post some code for you.

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