Skip to content

lordzsolt/BlockyGestures

Repository files navigation

BlockyGestures is a small framework written in Swift that allows you to create gesture recognizers that execute a closure instead of the old target-action pattern.

Features

  • Cocoapods support
  • Carthage support

Requirements

  • iOS 8.0+
  • Xcode 8.1+
  • Swift 3.0+

Usage

Simple use case

import BlockyGestures

let gesture = UITapGestureRecognizer().perfoming {
    // The code you would regularly put in the action selector
}

Specialized use case

You can perform different actions in each gesture recognizer state

import BlockyGestures

let gesture = UIPanGestureRecognizer()
gesture.performing(when: .ended) { 
    // Your code here
}

gesture.performing(when: [.began, .changed]) { 
    // Your other code here
}

NOTE: Currently you can only add a single closure for each gesture recognizer state.

Capturing gesture recognizer in closure

Currently the closure is of type () -> Void, so you will not recieve a reference to the gesture. To capture the gesute within the closure, you have to split your code like so:

let gesture = UISwipeGesture()
gesture.performing {
    // Your code here
}

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

CocoaPods 1.1.0+ is required to build BlockyGestures 1.0.0+.

To integrate BlockyGestures into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'BlockyGestures', '~> 1.0'
end

Then, run the following command:

$ pod install

Carthage

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 BlockyGestures into your Xcode project using Carthage, specify it in your Cartfile:

github "lordzsolt/BlockyGestures" ~> 1.0

Run carthage update to build the framework and drag the built BlockyGestures.framework into your Xcode project.

Communication

  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.

License

BlockyGestures is released under the MIT license. See LICENSE for details.

About

A library to add closure support for UIGestureRecognizer

Resources

License

Stars

Watchers

Forks

Packages

No packages published