Latest 1.0.0
Homepage https://github.com/shaps80/Snaply
License MIT
Platforms ios 8.0
Authors

Snap

Version
License
Language
Platform

Usage

The example project includes an example of a UICollectionViewFlowLayout including support for sections and spacing. It also includes support for snapping to the left, middle and right edges.

Lets add snapping support to our UICollectionView Snaply In Action
The following code is all that’s required to setup the top preview on the right.

let collectionView = UICollectionView(frame: view.bounds, 
collectionViewLayout: UICollectionViewFlowLayout())

// The delegate will automatically forward all events 
// to you existing delegate so it won't break your code :)
let snap = Snap(scrollView: collectionView, edge: .Min, 
direction: .Horizontal, delegate: self)

var locations = [CGFloat]()
var widths = [CGFloat]()

for i in 0..

How does it work

If we take a look at the following image, the red lines represent points we want our scrollView to snap to, along a given edge. So you just need to specify these points and Snaply will handle the snapping behaviour for you. Including things like finding the closest point and ensuring overscroll doens’t occur.

To get started, you just need a single line in your project:

snap = Snap(scrollView: collectionView, edge: .Min, direction: .Horizontal, delegate: self)

This adds snapping to the specified collectionView, using the left edge as the snap point since we’re using a horizontal layout.

You may notice we also pass along the original delegate (if any). This allows Snaply to automatically forward all events back to the original delegate to ensure no existing behaviour is effected by dropping in Snaply :)

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Snaply requires iOS 8+
The current version requires Swift 2.2

Installation

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

pod "Snaply"

Author

@shaps on Twitter

License

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

Latest podspec

{
    "name": "Snaply",
    "version": "1.0.0",
    "summary": "Drop-in snapping behaviour for any scroll/collection/table/view using arbitrary points!",
    "homepage": "https://github.com/shaps80/Snaply",
    "screenshots": "https://github.com/shaps80/Snaply/blob/master/snap.gif?raw=true",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Shaps": "[email protected]"
    },
    "source": {
        "git": "https://github.com/shaps80/Snaply.git",
        "tag": "1.0.0"
    },
    "social_media_url": "https://twitter.com/shaps",
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "Snaply/Classes/**/*"
}

Pin It on Pinterest

Share This