---
title: "#191: Taming Gesture Recognizers \u0026 Control Events with Tactile 👇"
url: https://littlebitesofcocoa.com/191-taming-gesture-recognizers-control-events-with-tactile
author: Jake Marsh
published: 2016-02-15
topics: ["Libraries","UIKit"]
description: "Today we'll check out a library called Tactile. It's a \"Swiftier\" way to respond to gesture recognizers and control events."
---

# #191: Taming Gesture Recognizers & Control Events with Tactile 👇

By Jake Marsh, February 15, 2016. HTML: https://littlebitesofcocoa.com/191-taming-gesture-recognizers-control-events-with-tactile

Today we'll check out a library called [Tactile](https://github.com/delba/Tactile). It's a "Swiftier" way to respond to **gesture recognizers** and **control events**. Let's get started.

[Tactile](https://github.com/delba/Tactile) gives us a safer, more idiomatic way to install/react to gesture recognizers (Check [Bite #38](https://littlebitesofcocoa.com/38) for gesture basics).

In it's simplest form, [Tactile](https://github.com/delba/Tactile) works like this:

``` swift
let tapGR = UITapGestureRecognizer()
tapGR.numberOfTapsRequired = 2

view.on(tapGR) { (tapGR: UITapGestureRecognizer) in
  // ...
}
```

We can also react to specific state changes:

``` swift
let panGR = UIPanGestureRecognizer()
view.on(panGR, [.Began, .Ended], beganOrEnded)

func beganOrEnded(panGR: UIPanGestureRecognizer) {
  // ...
}
```

[Tactile](https://github.com/delba/Tactile) also adds similar functions to **UIControl**:

``` swift
button.on(.TouchUpInside, tapped)
button.on([
  .TouchUpInside: tapped,
  .TouchUpOutside: cancelledTap
])
```

We can attach a single **recognizer** to multiple **views**:

``` swift
viewA.on(tapGR, { tapGR in /* ... */ })
viewB.on(tapGR, { tapGR in /* ... */ })
```

Last but not least, we can remove all **recognizers** with

``` swift
view.off()
```

just one with:

``` swift
view.off(tap)
```

or all of a type with:

``` swift
view.off(UITapGestureRecognizer.self)
```

More info about _Tactile_ can be found at [git.io/tactile](http://git.io/tactile)
