Swiftpack.co -  getmimo/SnappingLayout as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
getmimo/SnappingLayout
UICollectionViewFlowLayout with behaviour to snap the cell when scrolling.
.package(url: "https://github.com/getmimo/SnappingLayout.git", from: "0.1.4")

SnappingLayout

Version License Platform swift-version Carthage compatible swift-package-manager

:earth_americas: 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.

:coffee: Contents

🚥 Requirements

  • iOS 9.0+
  • Swift 4.2+

💻 Installation

CocoaPods

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:

pod 'SnappingLayout'

Then, run the following command:

$ pod install

Carthage

only available from version 0.1.2 onwards

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.

Swift Package Manager

only available from version 0.1.4 onwards

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"))
]

Manually

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.

🎓 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

💬 Contributing

This is an open source project, so feel free to contribute. How?

  • Open an issue;
  • Send feedback via email;
  • Propose your own fixes, suggestions and open a pull request with the changes.

See all contributors.

👨‍💻 Authors

👮 License

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

GitHub

link
Stars: 12
Last commit: 5 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

0.1.4
12 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.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API