SnappingLayout enables a snap behaviour for
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
contentInset and so forth.
CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
$ gem install cocoapods
To integrate SnappingLayout into your Xcode project using CocoaPods, specify it in your Podfile:
Then, run the following command:
$ pod install
only available from version
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with Homebrew using the following command:
$ brew update $ brew install carthage
To integrate SnappingLayout into your Xcode project using Carthage, specify it in your Cartfile:
github "SnappingLayout" ~> 0.1.2
Run carthage update to build the framework and drag the built SnappingLayout.framework into your Xcode project.
only available from version
Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.
To integrate SnappingLayout into your Xcode project using Swift Package Manager, add it to the dependencies value of your Package.swift:
dependencies: [ .package(url: "https://github.com/getmimo/SnappingLayout.git", .upToNextMajor(from: "0.1.4")) ]
If you prefer not to use either of the aforementioned dependency managers, you can always rely on the good old way of integrating SnappingLayout into your project manually.
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:
let snappingLayout = SnappingLayout()
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: snappingLayout)
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
This is an open source project, so feel free to contribute. How?
See all contributors.
SnappingLayout is available under the MIT license. See the LICENSE file for more info.
|Last commit: 2 weeks ago|
Fixed issue where UIKit wasn't found on the swift package by explicitly importing it and defining the iOS platform with minimum version to 9.