-->

UICollectionView Horizontal Scroll with Horizontal

2019-03-26 01:46发布

问题:

I would like to have a paged UICollectionView, with each page displaying cells from left to right. What I can achieve now with classic UICollectionViewFlowLayout and

layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;

The result is the following :

      page 1             page 2
 cell 1 | cell 3 || cell 5 | cell 7
 cell 2 | cell 4 || cell 6 | cell 8

What I would like to achieve now is:

      page 1             page 2
 cell 1 | cell 2 || cell 5 | cell 6
 cell 3 | cell 4 || cell 7 | cell 8

I would like to know if there is simpler solution than creating my own flow controller ? Or if not, is there some place where I can see the source code for UICollectionViewFlowLayout which is not so different of what I want ?

回答1:

I finally made my own layout subclassing UICollectionViewFlowLayout : I replace each cell's collectionViewAttributes with the corresponding one if it was a classic collectionViewFlowLayout, using a little bit of maths.

It now fits my needs, and could be useful for someone else, so here is my code: https://github.com/philippeauriach/fullyhorizontalcollectionview