SnappingLayout 0.1.4

SnappingLayout 0.1.4

Maintained by Kevin Cardoso de Sa, Dennis Daume, Helene Karlinger.



  • By
  • Kévin Cardoso de Sá

SnappingLayout

Version License Platform

Description

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.

Requirements

iOS 9.0

Swift 4.2

Installation

SnappingLayout is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'SnappingLayout'

Example Project

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.

Usage

Just use SnappingLayout as a replacement for the traditional UICollectionViewFlowLayout.

It's as simple as:

  1. Importing it:
import SnappingLayout
  1. Instantiating it:
let snappingLayout = SnappingLayout()
  1. And using it:
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: snappingLayout)
  1. Set the deceleration rate of the collection view to fast:
collectionView.decelerationRate = .fast

There are three types of snappingLayout: left, center and right.

Left

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

left

Center

This will snap the position of the cell to the center of the collection view.

let snappingLayout = SnappingLayout()
snappingLayout.snapPosition = .center

center

Right

This will snap the position of the cell to the right of the collection view.

let snappingLayout = SnappingLayout()
snappingLayout.snapPosition = .right

right

Author

Kévin, [email protected]

License

SnappingLayout is available under the MIT license. See the LICENSE file for more info.