0

I'm making an paging UICollectionView and use KRLCollectionViewGridLayout for custom 3x3 grid layout. Everything in first page run perfectly like image below with this settings:

KRLCollectionViewGridLayout *flowLayout = [[KRLCollectionViewGridLayout alloc] init];
flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
flowLayout.aspectRatio = 1;
flowLayout.sectionInset = UIEdgeInsetsMake(2, 25, 10, 15);
flowLayout.interitemSpacing = 25;
flowLayout.lineSpacing = 25;
flowLayout.numberOfItemsPerLine = 3;

enter image description here

But when I'm scrolled to second page, the problem start: The content offset of my collection being misaligned like this image, it isn't grid 3x3 anymore:

enter image description here

I take a night for research the solution but seem like they're not help me to solve this problem. How can I fix it now?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Bad_Developer
  • 537
  • 5
  • 20
  • how are you calculating cell size? – cyril Nov 03 '18 at 11:02
  • @cyril using `KRLCollectionViewGridLayout` is auto estimate the cell size. I just need to set `flowLayout.numberOfItemsPerLine = 3;` then it will fit with my collection frame. – Bad_Developer Nov 04 '18 at 03:34
  • Maybe the unintended effects you are seeing are due to the library? Have you tried a) achieving the layout without using the library b) using the library in a separate empty project? – cyril Nov 04 '18 at 08:29
  • Yes I did, after using that lib and got error I've setting UICollectionViewFlowLayout manually and still get this problem: `UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal; flowLayout.minimumInteritemSpacing = 10; flowLayout.minimumLineSpacing = 25; flowLayout.sectionInset = UIEdgeInsetsMake(2, 25, 10, 15); flowLayout.itemSize = CGSizeMake(90, 90);` – Bad_Developer Nov 04 '18 at 08:33
  • Just realized you're trying to center collection view cells while paging. Have you tried [this](https://stackoverflow.com/questions/29658328/uicollectionview-horizontal-paging-not-centered)? – cyril Nov 04 '18 at 09:29
  • Of course, I tried but it's not work with my problem – Bad_Developer Nov 04 '18 at 10:47

0 Answers0