I need to show 3 items in a UICollectionView, with paging enabled like this
but I am getting like this
I have made custom flow, plus paging is enabled but not able to get what i need. How can i achieve this or which delegate should i look into, or direct me to some link from where i can get help for this scenario.
- (void)awakeFromNib
{
self.itemSize = CGSizeMake(480, 626);
self.minimumInteritemSpacing = 112;
self.minimumLineSpacing = 112;
self.scrollDirection = UICollectionViewScrollDirectionHorizontal;
self.sectionInset = UIEdgeInsetsMake(0, 272, 0, 272);
}
Part one of @Raheel Sadiq answer in Swift 3, without Transform.
you will have to override targetContentOffsetForProposedContentOffset:withScrollingVelocity: method of the flow layout. This way you snap the stopping point of the scrollview.
Also you will beed to set the sectionInset of the flow layout to center the first cell and the last cell. My example is the height but easy to switch to width.
Edit: Demo link: https://github.com/raheelsadiq/UICollectionView-horizontal-paging-with-3-items
After a lot searching I did it, find the next point to scroll to and disable the paging. In scrollviewWillEndDragging scroll to next cell x.
I also had to make the left and right small and center large, so i did it with transform. The issue was finding the index, so that was very difficult to find.
For transform left and right in this same method use the newTargetOffset
And in cellForRowAtIndex add
Add these two macros too or as u wish to handle both
The end result is
@raheel-sadiq answer is great but pretty hard to understand, I think. Here's a much readable version, in my opinion:
Swift 3.0 Complete Solution based on Raheel Sadiq