|
4 | 4 | [](https://cocoapods.org/pods/SnappingLayout) |
5 | 5 | [](https://cocoapods.org/pods/SnappingLayout) |
6 | 6 |
|
7 | | -## Example |
| 7 | +## Description |
8 | 8 |
|
9 | | -To run the example project, clone the repo, and run `pod install` from the Example directory first. |
| 9 | +**SnappingLayout** enables a snap behaviour for `UICollectionViews`. |
| 10 | +It works with horizontal scrolling and there are 3 different types: left, center and right. |
| 11 | +You can scroll your collection view and it will automatically snap to the chosen position after decelerating. |
| 12 | + |
| 13 | +The snap supports all kinds of collection view configurations: with `sectionInset`, `minimumLineSpacing`, `contentInset` and so forth. |
10 | 14 |
|
11 | 15 | ## Requirements |
12 | 16 |
|
13 | 17 | iOS 9.0 |
| 18 | + |
14 | 19 | Swift 4.2 |
15 | 20 |
|
16 | 21 | ## Installation |
17 | 22 |
|
18 | | -SnappingLayout is available through [CocoaPods](https://cocoapods.org). To install |
| 23 | +**SnappingLayout** is available through [CocoaPods](https://cocoapods.org). To install |
19 | 24 | it, simply add the following line to your Podfile: |
20 | 25 |
|
21 | 26 | ```ruby |
22 | 27 | pod 'SnappingLayout' |
23 | 28 | ``` |
24 | 29 |
|
| 30 | +## Example Project |
| 31 | + |
| 32 | +To run the example project, clone the repo, and run pod install from the Example directory first. |
| 33 | +Open **SnappingPresentationViewController** to see the code needed to implement the snapping. |
| 34 | + |
| 35 | +## Usage |
| 36 | + |
| 37 | +Just use **SnappingLayout** as a replacement for the traditional **UICollectionViewFlowLayout**. |
| 38 | + |
| 39 | +It's as simple as: |
| 40 | +1. Importing it: |
| 41 | +``` |
| 42 | +import SnappingLayout |
| 43 | +``` |
| 44 | +2. Instantiating it: |
| 45 | +``` |
| 46 | +let snappingLayout = SnappingLayout() |
| 47 | +``` |
| 48 | +3. And using it: |
| 49 | +``` |
| 50 | +let collectionView = UICollectionView(frame: .zero, collectionViewLayout: snappingLayout) |
| 51 | +``` |
| 52 | +4. Set the deceleration rate of the collection view to fast: |
| 53 | +``` |
| 54 | +collectionView.decelerationRate = .fast |
| 55 | +``` |
| 56 | + |
| 57 | +There are three types of `snappingLayout`: left, center and right. |
| 58 | + |
| 59 | +### Left |
| 60 | + |
| 61 | +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. |
| 62 | + |
| 63 | +``` |
| 64 | +let snappingLayout = SnappingLayout() |
| 65 | +snappingLayout.snapPosition = .left |
| 66 | +``` |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | +### Center |
| 71 | + |
| 72 | +This will snap the position of the cell to the center of the collection view. |
| 73 | + |
| 74 | +``` |
| 75 | +let snappingLayout = SnappingLayout() |
| 76 | +snappingLayout.snapPosition = .center |
| 77 | +``` |
| 78 | + |
| 79 | + |
| 80 | + |
| 81 | +### Right |
| 82 | + |
| 83 | +This will snap the position of the cell to the right of the collection view. |
| 84 | + |
| 85 | +``` |
| 86 | +let snappingLayout = SnappingLayout() |
| 87 | +snappingLayout.snapPosition = .right |
| 88 | +``` |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | + |
25 | 93 | ## Author |
26 | 94 |
|
27 | 95 | |
|
0 commit comments