Gesture Recognizers

The UIGestureRecognizer initializers and delegation wrappers make it easy to add gesture recognizers to views. It also uses closures instead of target-action and delegation.

Target-Action Initializers

The following is how you would add a double tap gesture recognizer to your view using one of the custom initializers. As always, we have a closure handler to respond to the gesture’s double tap action.

let doubleTapGesture = UITapGestureRecognizer(tapsRequired: 2) { _ in
    log("double tapped")

These convenience initializers, delegate closures, and closure recognizers have been added to all of the existing concrete subclasses, including:

  • UITapGestureRecognizer
  • UIPinchGestureRecognizer
  • UIRotationGestureRecognizer
  • UISwipeGestureRecognizer
  • UIPanGestureRecognizer
  • UIScreenEdgePanGestureRecognizer
  • UILongPressGestureRecognizer

There is also a method for you to configure a custom gesture recognizer to use closure handlers for recognition:

let myCustomGesture = MyCustomGestureRecognizer()
configure(gesture: myCustomGesture) { _ in
    /// a closure that's called when the gesture has ended


With convenient extension methods on UIGestureRecognizer and UIView, we can daisy chain an entire gesture cycle, including responding to UIGestureRecognizerDelegate methods.

    .addPanGesture() { pan in
        guard pan.state == .ended else { return }
        log("view panned")
    }.shouldBegin() {
    }.shouldRecognizeSimultaneouslyWith {
        $0 === doubleTapGesture