ProductPromotion
Logo

Swift

made by https://0x3d.site

GitHub - delba/Tactile: A better way to handle gestures on iOS
A better way to handle gestures on iOS. Contribute to delba/Tactile development by creating an account on GitHub.
Visit Site

GitHub - delba/Tactile: A better way to handle gestures on iOS

GitHub - delba/Tactile: A better way to handle gestures on iOS

Tactile is a safer and more idiomatic way to respond to gestures and control events. It lets you catch bugs at compile time and write more expressive code.

view.pan([
    .began:   panBegan,
    .changed: panChanged,
    .ended:   panEnded
])

// func panBegan(pan: UIPanGestureRecognizer)
// func panChanged(pan: UIPanGestureRecognizer)
// func panEnded(pan: UIPanGestureRecognizer)

Usage

Tactile extends both UIView and UIControl classes.

UIView extensions

UIView+Tactile.swift

The on method

Use the on method to add gesture recognizers.

on(gesture:callback:)

let tap = UITapGestureRecognizer()
tap.numberOfTapsRequired = 3
tap.numberOfTouchesRequired = 2

view.on(tap, tapped)

// func tapped(tap: UITapGestureRecognizer)

on(gesture:state:callback:)

let pinch = UIPinchGestureRecognizer()

view.on(pinch, .began, pinchBegan)

// func pinchBegan(pinch: UIPinchGestureRecognizer)

on(gesture:states:callback:)

let pan = UIPanGestureRecognizer()

view.on(pan, [.began, .ended], panBeganOrEnded)

// func panBeganOrEnded(pan: UIPanGestureRecognizer)

on(gesture:callbacks:)

let pinch = UIPinchGestureRecognizer()

view.on(pinch, [
  .began: pinchBegan,
  .ended: pinchEnded
])

// func pinchBegan(pinch: UIPinchGestureRecognizer)
// func pinchEnded(pinch: UIPinchGestureRecognizer)

The shorthand methods

Tactile defines 6 shorthand methods: longPress, pan, pinch, rotation, swipe and tap.

<shorthand>(callback:)

view.tap(tapped)

// func tapped(tap: UITapGestureRecognizer)

<shorthand>(state:callback:)

view.pinch(.began, pinchBegan)

// func pinchBegan(pinch: UIPinchGestureRecognizer)

<shorthand>(states:callback:)

view.pan([.began, .ended], panBeganOrEnded)

// func panBeganOrEnded(pan: UIPanGestureRecognizer)

<shorthand>(callbacks:)

view.longPress([
  .began: longPressBegan,
  .ended: longPressEnded
])

// func longPressBegan(longPress: UILongPressGestureRecognizer)
// func longPressEnded(longPress: UILongPressGestureRecognizer)

The off method

Use the off method to remove gesture recognizers.

off(gesture:)

let tap = UITapGestureRecognizer()
view.on(tap, tapped)

// ...

view.off(tap)

off(gestureType:)

view.off(UITapGestureRecognizer.self)

off()

view.off()

Attaching a gesture recognizer to multiple views

With Tactile, you can attach the same gesture recognizer to multiple views.

let tap = UITapGestureRecognizer()
tap.numberOfTapsRequired = 3
tap.numberOfTouchesRequired = 2

firstView.on(tap, firstViewTapped)
secondView.on(tap, secondViewTapped)

UIControl extensions

UIControl+Tactile.swift

Use the on method to attach an event handler function for one or more control events.

on(event:callback:)

button.on(.touchUpInside, tapped)

// func tapped(button: UIButton)

on(events:callback:)

button.on([.touchUpInside, .touchUpOutside], tapped)

// func tapped(button: UIButton)

on(callbacks:)

button.on([
  .touchUpInside: tapped,
  .touchUpOutside: cancelledTap
])

// func tapped(button: UIButton)
// func cancelledTap(button: UIButton)

Installation

Carthage

Carthage is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate Tactile into your Xcode project using Carthage, specify it in your Cartfile:

github "delba/Tactile" >= 1.0

CocoaPods

CocoaPods is a dependency manager for Cocoa projects.

You can install it with the following command:

$ gem install cocoapods

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

use_frameworks!

pod 'Tactile', '~> 1.0'

License

Copyright (c) 2015-2019 Damien (http://delba.io)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here ๐Ÿ”.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory