UICollectionView Bring the item to the center position

I used collectionview to show models as well as years, and the user can sweep through the cells.

The selected cell will be located in the center, regardless of the number of elements.

Any help would be greatly appreciated.

+6
source share
1 answer

SOL 1:

collectionView.scrollToItemAtIndexPath(indexPath, atScrollPosition: .CenteredHorizontally, animated: true) 

SOL 2: I suggest you add empty objects at the beginning and at the end. Thus, the user can scroll the first and last visible element in the center.

+12
source

All Articles