Special way to work with gestures in iOS

Overview

Sensitive

At a Glance

Sensitive is a library that simplifies work with gestures in iOS. Forget about target/action pattern of primitive UIGestureRecognizer. With Sensitive you can call onTap, onPinch, onSwipe on any UIView instance and implement handler for the gesture. That's all that you should know to start. For details, see Usage section.

How To Get Started

  • Copy content of Source folder to your project.

or

  • Use Sensitive cocoapod.

Requirements

  • iOS 9.0 and later
  • Xcode 9.0 and later
  • Swift 4.1 or later

Usage

Adding Gesture Recognizers to View

All gestures are available via special variables that you can call on any UIView instance. Examples:

view.onTap
    .configure(with: { (gestureRecognizer) in
        // Configure `UITapGestureRecognizer` instance
        gestureRecognizer.numberOfTapsRequired = 2
    })
    .handle { (gestureRecognizer) in
        // Handle tap on view
        gestureRecognizer.view!.backgroundColor = .green
    }

view.onSwipe
    .configure(with: { (gestureRecognizer) in
        // Configure `UISwipeGestureRecognizer` instance
        gestureRecognizer.direction = .left
    })
    .handle { (gestureRecognizer) in
        // Handle tap on view
        gestureRecognizer.view!.backgroundColor = .green
    }

Full list of available gestures:

  • onTap
  • onLongPress
  • onPan
  • onPinch
  • onRotation
  • onSwipe
  • onScreenEdgePan

Simultaneous Recognition

If you need few gestures to work together on the same view, you can also use recognizeSimultaneously method:

view.onTap
    .handle { (gestureRecognizer) in
        // Your implementation here...
    }
    .recognizeSimultaneously(true)

view.onPinch
    .handle { (gestureRecognizer) in
        // Your implementation here...
    }
    .recognizeSimultaneously(true)

License

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

You might also like...
Work-hours-mac - Simple app that tracks your work hours from the status bar
Work-hours-mac - Simple app that tracks your work hours from the status bar

Track Your Work Hours Simple app that tracks your work hours from status bar. Fe

Examples projects using SwiftUI released by WWDC2019. Include Layout, UI, Animations, Gestures, Draw and Data.
Examples projects using SwiftUI released by WWDC2019. Include Layout, UI, Animations, Gestures, Draw and Data.

SwiftUI Examples About Examples projects using SwiftUI & Combine. Include Layout, UI, Animations, Gestures, Draw and Data. See projects files in Files

RxSwift reactive wrapper for view gestures
RxSwift reactive wrapper for view gestures

RxGesture Usage To run the example project, clone the repo, in the Example folder open RxGesture.xcworkspace. You might need to run pod install from t

BabySortingToyGame - Build a little game for babies to sort shapes in the correct location. This is made in SwiftUI using drag gestures.
BabySortingToyGame - Build a little game for babies to sort shapes in the correct location. This is made in SwiftUI using drag gestures.

This is a demo to build a little mini-game "for babies". It's inspired in this kind of games:

GesturesSwiftUI - A simple project to demonstrate how gestures works in SwiftUI

GesturesSwiftUI - A simple project to demonstrate how gestures works in SwiftUI

Easily use ARKit to detect facial gestures.
Easily use ARKit to detect facial gestures.

Easily use ARKit to detect facial gestures. FaceTrigger is a simple to use class that hides the details of using ARKit's ARSCNView to recognize facial gestures via ARFaceAnchor.BlendShapeLocations

Easy way to detect iOS device properties, OS versions and work with screen sizes. Powered by Swift.
Easy way to detect iOS device properties, OS versions and work with screen sizes. Powered by Swift.

Easy way to detect device environment: Device model and version Screen resolution Interface orientation iOS version Battery state Environment Helps to

A simpler way to work with NSLayoutAnchor
A simpler way to work with NSLayoutAnchor

SugarAnchor is syntactic sugar on NSLayoutAnchor to help us write more compact, readable and easy layout code. It wraps up all of NSLayoutXAxisAnchor,

An app that will help UI/UX designers and iOS developpers to easily work together, using demos and examples about iOS capabilities, limitations, ecosystem, ...

Demoapp Work in progress... 👀 What's about? It's an app built in SwiftUI that will help UI/UX designers and iOS developpers to work together smoothly

RSA public/private key encryption, private key signing and public key verification in Swift using the Swift Package Manager. Works on iOS, macOS, and Linux (work in progress).

BlueRSA Swift cross-platform RSA wrapper library for RSA encryption and signing. Works on supported Apple platforms (using Security framework). Linux

SimpleAuth is designed to do the hard work of social account login on iOS

SimpleAuth is designed to do the hard work of social account login on iOS. It has a small set of public APIs backed by a set of "providers"

RSA public/private key encryption, private key signing and public key verification in Swift using the Swift Package Manager. Works on iOS, macOS, and Linux (work in progress).

BlueRSA Swift cross-platform RSA wrapper library for RSA encryption and signing. Works on supported Apple platforms (using Security framework). Linux

GraphQLite is a toolkit to work with GraphQL servers easily. It also provides several other features to make life easier during iOS application development.
GraphQLite is a toolkit to work with GraphQL servers easily. It also provides several other features to make life easier during iOS application development.

What is this? GraphQLite is a toolkit to work with GraphQL servers easily. It also provides several other features to make life easier during iOS appl

Pre-work: A tip calculator application for iOS
Pre-work: A tip calculator application for iOS

Pre-work - Tip Calculator Tip Calculator is a tip calculator application for iOS. Submitted by: Jonathan Ballona Sanchez Time spent: 7 hours spent in

An original digital art work for macOS, iOS and web
An original digital art work for macOS, iOS and web

WordClock WordClock versions of various vintages, for various platforms. https://www.simonheys.com/wordclock/ Downloads Currently avaiaible to downloa

Reverie is a work-in-progress iOS app that displays your Last.fm scrobbles for each past year, for the current date.
Reverie is a work-in-progress iOS app that displays your Last.fm scrobbles for each past year, for the current date.

Reverie is a work-in-progress iOS app that displays your Last.fm scrobbles for each past year, for the current date.

TaskManager-CoreData - Swift IOS Application created primarily to familiarize with the CoreData framework and gain knowledge to work with it iOS library for device fingerprinting. Does not require server APIs to work, fully client-side operation.
iOS library for device fingerprinting. Does not require server APIs to work, fully client-side operation.

Lightweight iOS library for local device fingerprinting Installation (CocoaPods) # Podfile pod 'FingerprintJS' Note: If you've never used CocoaPods fo

A highly experimental, self-custody Lightning wallet built to work for iOS and macOS.

Surge Surge is a highly experimental, self-custody Lightning wallet built to work for iOS and macOS. Motivation Tools and infrastructure for running a

Comments
  • Remove KVO Observer before deallocating

    Remove KVO Observer before deallocating

    We experienced a crash when deallocating GestureRecognizers, specifically on iOS 10 devices.

    Crash report reads as follows:

    Fatal Exception: NSInternalInconsistencyException An instance 0x1703a5a20 of class UITapGestureRecognizer was deallocated while key value observers were still registered with it. Current observation info: <NSKeyValueObservationInfo 0x17023d8c0> ( <NSKeyValueObservance 0x170651fd0: Observer: 0x17045fb60, Key path: view, Options: <New: YES, Old: NO, Prior: NO> Context: 0x0, Property: 0x17044f720> )

    Full stack trace:

    Fatal Exception: NSInternalInconsistencyException
    0  CoreFoundation                 0x18a8fafe0 __exceptionPreprocess
    1  libobjc.A.dylib                0x18935c538 objc_exception_throw
    2  CoreFoundation                 0x18a8faf28 -[NSException initWithCoder:]
    3  Foundation                     0x18b356120 NSKVODeallocate
    4  Sensitive                      0x1011b7f54 Gesture.__deallocating_deinit (Gesture.swift:38)
    5  Sensitive                      0x1011b7fe8 @objc Gesture.__deallocating_deinit (<compiler-generated>)
    6  Tingles                        0x1002159fc ArtistTableViewCell.prepareForReuse() (ArtistTableViewCell.swift:150)
    7  Tingles                        0x100215aa8 @objc ArtistTableViewCell.prepareForReuse() (<compiler-generated>)
    8  UIKit                          0x190b694b4 -[UITableView _dequeueReusableViewOfType:withIdentifier:]
    9  Tingles                        0x1003aa3a8 __32+[UITableView(TLTableView) load]_block_invoke_2.69
    10 UIKit                          0x190ba3cc8 -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:]
    11 Tingles                        0x1003aa138 __32+[UITableView(TLTableView) load]_block_invoke_2.38
    12 JSQDataSourcesKit              0x1009edd00 @objc UITableView.dequeueReusableCellFor(identifier:indexPath:) (ViewFactory.swift:84)
    13 JSQDataSourcesKit              0x1009ed494 ReusableViewFactoryProtocol<>.tableCellFor(item:tableView:indexPath:) (ViewFactory.swift:224)
    14 JSQDataSourcesKit              0x1009e7498 closure #3 in DataSourceProvider<>.tableViewBridgedDataSource()
    15 JSQDataSourcesKit              0x1009e7af8 partial apply for closure #3 in DataSourceProvider<>.collectionViewBridgedDataSource()
    16 JSQDataSourcesKit              0x1009e24e0 @objc BridgedDataSource.collectionView(_:cellForItemAt:)
    17 UIKit                          0x190d711f8 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:]
    18 UIKit                          0x190d71410 -[UITableView _createPreparedCellForGlobalRow:willDisplay:]
    19 UIKit                          0x190d5eb14 -[UITableView _updateVisibleCellsNow:isRecursive:]
    20 UIKit                          0x190d76400 -[UITableView _performWithCachedTraitCollection:]
    21 UIKit                          0x190b0e858 -[UITableView layoutSubviews]
    22 UIKit                          0x190a2907c -[UIView(CALayerDelegate) layoutSublayersOfLayer:]
    23 QuartzCore                     0x18dc19274 -[CALayer layoutSublayers]
    24 QuartzCore                     0x18dc0dde8 CA::Layer::layout_if_needed(CA::Transaction*)
    25 QuartzCore                     0x18dc0dca8 CA::Layer::layout_and_display_if_needed(CA::Transaction*)
    26 QuartzCore                     0x18db8934c CA::Context::commit_transaction(CA::Transaction*)
    27 QuartzCore                     0x18dbb03ac CA::Transaction::commit()
    28 QuartzCore                     0x18dbb0e78 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*)
    29 CoreFoundation                 0x18a8a89a8 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__
    30 CoreFoundation                 0x18a8a6630 __CFRunLoopDoObservers
    31 CoreFoundation                 0x18a8a6a7c __CFRunLoopRun
    32 CoreFoundation                 0x18a7d6da4 CFRunLoopRunSpecific
    33 GraphicsServices               0x18c240074 GSEventRunModal
    34 UIKit                          0x190a91058 UIApplicationMain
    35 Tingles                        0x1000db73c main (ActionControllerExtension.swift:30)
    36 libdyld.dylib                  0x1897e559c start
    

    Removing the observer before releasing the gesture recognizer fixes this issue.

    opened by zweigraf 0
Owner
Igor M.
Software engineer and project manager. Making this world a much better place. Wanna talk? Drop me a line to [email protected]
Igor M.
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

Damien 714 Dec 29, 2022
The easiest way to show off your iOS taps and gestures for demos and videos.

It's ShowTime ?? Installation Swift Package Manager Cocoapods Manual Usage How it works Useful info Author License ShowTime is the simplest and best w

Kane Cheshire 459 Dec 27, 2022
Best way to use UIGesture

NiceGesture The best way to use UIGesture #Usage ###TapGesture: because tapGesture is only have one state,so it's only have method whenTapped view.n

Zhuo 104 Sep 9, 2022
Gesture recognizer tool [Swift / iOS]

DBPathRecognizer Demo Installation Simply add the file DBPathRecognizer.swift to your project Basic usage Start by creating a new DBPathRecognizer ins

Didier Brun 1.2k Dec 18, 2022
Drag and drop between your apps in split view mode on iOS 9

SplitViewDragAndDrop Easily add drag and drop to pass data between your apps Setup Add pod 'SplitViewDragAndDrop' to your Podfile or copy the "SplitVi

Mario Iannotta 324 Nov 22, 2022
Special way to work with gestures in iOS

At a Glance Sensitive is a library that simplifies work with gestures in iOS. Forget about target/action pattern of primitive UIGestureRecognizer. Wit

Igor M. 550 Dec 29, 2022
XShared - Xcode extension that allows you copying the code with special formatting quotes for social (Slack, Telegram)

This extension is for those who like to show code to the public ?? Xcode extension which allows you copying the code with special formatting quotes fo

Nikita Ermolenko 75 Jun 18, 2022
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

Damien 714 Dec 29, 2022
The easiest way to show off your iOS taps and gestures for demos and videos.

It's ShowTime ?? Installation Swift Package Manager Cocoapods Manual Usage How it works Useful info Author License ShowTime is the simplest and best w

Kane Cheshire 459 Dec 27, 2022
A script for focusing on work, blocking non-work stuff.

A script for focusing on work, blocking non-work stuff. The idea is to forbid mindless app/website context-switching while you're focused. Once you're

null 3 Jan 23, 2022