Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to layout UICollectionView with tabbar on SupplementaryView, and switching different content?

I want to implement the UICollectionView effect with tabbar and possible to switch different content like a lot of social app does.

enter image description here

You can click Home to display timeline and click Album to display photos on content area. The top of content like avatar and username are no change, and the content offset will keep the same when you switch is completed.

I try it with a UICollectionView containing SupplementaryView for displaying avatar and handling tabbar click event. Assign different delegate, dataSource and layout object while switching different content. But I got a lot of problem and crash.

What's the correct way to implement this kind of layout and how to handle switching event?

like image 742
Angolao Avatar asked Jan 05 '16 17:01

Angolao


2 Answers

If I understand correctly the top part of your view does not change and remains as the logo with an avatar. If this is the case I would not worry about supplementary views. Supplementary views are more for section headers/separators in a similar way to the use of section headers for UITableViews. Instead have a container view at the bottom which would hold the collectionView with UISegmentedControl above which would trigger the changes in the container view. If the container is to display the same data with different layouts (ie. photos scrolling vertically to horizontally) then the segmented control could trigger a change to the collectionViewFlowLayout but if the data changes (ie Timeline to Album) then I would suggest switching to different child view controllers in the container view triggered from the segmented control actions. You would probably want to save the current scroll offset in the container view controllers so that it can be restored when switching back. Also having separate child view controller classes will help prevent the container view controller from getting too large and keep each child collection view controller simple and focused.

like image 113
Dallas Johnson Avatar answered Nov 07 '22 14:11

Dallas Johnson


Just decompose your logic, there is no necessity to keep everything in one UICollectionView and switch data sources and delegates.

like image 35
Anton Tyutin Avatar answered Nov 07 '22 14:11

Anton Tyutin