SnappingLayout enables a snap behaviour for UICollectionViews.
It works with horizontal scrolling and there are 3 different types: left, center and right.
You can scroll your collection view and it will automatically snap to the chosen position after decelerating.
The snap supports all kinds of collection view configurations: with sectionInset, minimumLineSpacing, contentInset and so forth.
iOS 9.0
Swift 4.2
SnappingLayout is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'SnappingLayout'To run the example project, clone the repo, and run pod install from the Example directory first. Open SnappingPresentationViewController to see the code needed to implement the snapping.
Just use SnappingLayout as a replacement for the traditional UICollectionViewFlowLayout.
It's as simple as:
- Importing it:
import SnappingLayout
- Instantiating it:
let snappingLayout = SnappingLayout()
- And using it:
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: snappingLayout)
- Set the deceleration rate of the collection view to fast:
collectionView.decelerationRate = .fast
There are three types of snappingLayout: left, center and right.
This is the default value when a new instance of snappingLayout is created and it will snap the position of the cell to the left side of the collection view.
let snappingLayout = SnappingLayout()
snappingLayout.snapPosition = .left
This will snap the position of the cell to the center of the collection view.
let snappingLayout = SnappingLayout()
snappingLayout.snapPosition = .center
This will snap the position of the cell to the right of the collection view.
let snappingLayout = SnappingLayout()
snappingLayout.snapPosition = .right
Kévin, [email protected]
SnappingLayout is available under the MIT license. See the LICENSE file for more info.


