Gesture recognizer tool [Swift / iOS]

Overview

DBPathRecognizer

Demo

ScreenShot

Installation

Simply add the file DBPathRecognizer.swift to your project

Basic usage

Start by creating a new DBPathRecognizer instance

// Create the path 8-directions path recognizer with a delta move sensibility of 16 pt
let recognizer = DBPathRecognizer(sliceCount: 8, deltaMove: 16.0)

Note that you can specify a max cost to recognize the gestures. It means that if a gesture has a score greater than costMax, it will be ignored.

let recognizer = DBPathRecognizer(sliceCount: 8, deltaMove: 16.0, costMax: 40)

Add some path model to the recognizer. Each path is defined by a direction-sequence and an associated data object (AnyObject).

recognizer.addModel(PathModel(directions: [7, 1], datas:"A"))
recognizer.addModel(PathModel(directions: [2,6,0,1,2,3,4,0,1,2,3,4], datas:"B"))
recognizer.addModel(PathModel(directions: [4,3,2,1,0], datas:"C"))
recognizer.addModel(PathModel(directions: [4,3,2,1,0,4,3,2,1,0], datas:"E"))

For example, here the model for the letter E :

ScreenShot

Record a touch move sequence into the dedicated Path structure :

// Create the path
var path:Path = Path()

// Add a point (from touch location)
path.addPoint(PathPoint(x:100, y:100)) 

// You can also use the convenient method addPointFromRaw(var rawDatas:[Int])
path.addPointFromRaw(rawPoints)

Finally, tell the recognizer to find the best model :

var gesture:PathModel? = self.recognizer!.recognizePath(path)
        
if gesture != nil {
    // The best gesture is recognized
} else {
    // No gesture recognized (score is too low)
}

Custom filter

While adding a model, you can specify a custom filter. The filter callback method, if specified, will let you a last chance to modify / analyze the datas to determine a new score.

For example, the letter D & P have a similar draw-direction-path, however you can discriminate each one by detecting the position of the last point (up -> it's a P, down -> it's a D). The PathInfos struct transmited to the filter function will help you to determine the new score.

Your custom filter function should conform to this signature : ((score:Int, infos:PathInfos) -> newScore:Int) :

recognizer.addModel(PathModel(directions: [2,6,7,0,1,2,3,4], datas:"P", filter:{
            (cost:Int, infos:PathInfos) -> Int in
                // Determine new cost
                return cost
        }));

Free path

In this sample project I've used the Graffiti alphabet for the didactic aspect. However, PathRecognizer is a generic algorithm, you can add any free path to control an interface / game :

ScreenShot

You might also like...
The right way to increment/decrement values with a simple gesture on iOS.
The right way to increment/decrement values with a simple gesture on iOS.

barceloneta The right way to increment/decrement values barceloneta is the right way to increment/decrement values with a simple gesture on iOS Featur

Hand-gesture recognition on iOS app using CoreML
Hand-gesture recognition on iOS app using CoreML

GestureAI-CoreML-iOS Hand-gesture recognizer using CoreML Demo Screenshots This app is using RNN(Recurrent Neural network) with CoreML on iOS11. The m

Awesome IOS Styling with SwiftUI, Animation, Effects, Gesture ⭐️

Awesome SwiftUI Styling with SwiftUI ⭐️ This repository is dedicated to IOS styling using SwiftUI. (often using Other Libraries.) I started collecting

Swift interpolation for gesture-driven animations
Swift interpolation for gesture-driven animations

Interpolate Interpolate is a powerful Swift interpolation framework for creating interactive gesture-driven animations. Usage The 🔑 idea of Interpola

🖐 Memory game with hand gesture recognition that will keep your brain in a good shape!
🖐 Memory game with hand gesture recognition that will keep your brain in a good shape!

Hands I have always been interested in how I can improve my memory in addition to reading books, and once I came across an interesting technique relat

TextDrawer, is a UIView allows you to add text, with gesture, on UIView, or UIImage
TextDrawer, is a UIView allows you to add text, with gesture, on UIView, or UIImage

TextDrawer TextDrawer, is a UIView allows you to add text, with gesture, on UIView, or UIImage. About Annotating Images TextDrawer is the easiest way

One gesture, many actions. An evolution of Pull to Refresh.
One gesture, many actions. An evolution of Pull to Refresh.

MNTPullToReact MNTPullToReact is an extended evolution of the famous Pull to Refresh interaction. The main idea comes from a unique question: can the

A UINavigationController's category to enable fullscreen pop gesture with iOS7+ system style.
A UINavigationController's category to enable fullscreen pop gesture with iOS7+ system style.

FDFullscreenPopGesture An UINavigationController's category to enable fullscreen pop gesture in an iOS7+ system style with AOP. Overview 这个扩展来自 @J_雨 同

Simple motion detector for ⌚️ (watchOS) shake gesture.
Simple motion detector for ⌚️ (watchOS) shake gesture.

WatchShaker Simple motion detector for ⌚️ (watchOS) shake gesture. WatchShaker is a watchOS helper to get your ⌚️ shake movements Requirements watchOS

Drag gesture modifier to easily apply to any view.

SwiftUIDragModifier A description of this package. This is my first SwiftUI Package. It provides a quick way to make any SwiftUI View draggable. After

Simple example of view that appears on tap button and  dismiss with swipe gesture.
Simple example of view that appears on tap button and dismiss with swipe gesture.

MenuWithSlide Simple SwiftUI example of how to show side menu with slide effect. On button press - appeares, on background tap or swipe right - dissmi

Designed for gesture-driven animations. Fast, simple, & extensible!
Designed for gesture-driven animations. Fast, simple, & extensible!

Yet Another Animation Library Designed for gesture-driven animations. Fast, simple, & extensible! It is written in pure swift 3.1 with protocol orient

Card flip animation by pan gesture.

CardAnimation Design from Dribble. 实现思路在这里。 Two Solutions At the begin, I didn't encapsulate code, @luxorules refactor code into class and improve it

a TableView have thumbnail cell only, and you can use gesture let it expands other expansionView, all diy
a TableView have thumbnail cell only, and you can use gesture let it expands other expansionView, all diy

ZYThumbnailTableView #####可展开型预览TableView,开放接口,完全自由定制 #####An expandable preview TableView, custom-made all the modules completely with open API you c

A non gesture blocking, non clipping by default custom scroll view implementation with example code

A non gesture blocking, non clipping by default custom scroll view implementation with example code

OpenSwiftUIViews - A non gesture blocking, non clipping by default custom scroll view implementation with example code.

OpenSwiftUIViews - A non gesture blocking, non clipping by default custom scroll view implementation with example code.

You can dismiss modal by using gesture
You can dismiss modal by using gesture

RPModalGestureTransition You can dismiss modal by using gesture. Usage 1.Define animation You define animator class inherits UIViewControllerAnimatedT

Allows trendy transitions using swipe gesture such as
Allows trendy transitions using swipe gesture such as "swipe back anywhere".

SwipeTransition allows trendy transitions using swipe gesture such as "swipe back". Try the demo on the web (appetize.io): https://appetize.io/app/peb

In SwiftUI, a property-wrapper provides velocity in pt/s from gesture
In SwiftUI, a property-wrapper provides velocity in pt/s from gesture

swiftui-GestureVelocity In SwiftUI, a property-wrapper provides velocity in pt/s from gesture Instructions @GestureVelocity private var velocity: CGVe

Comments
  • How to use custom filter

    How to use custom filter

    Hey Didier (or anyone reading)

    I'm trying to use this great library for a game I'm making, but it seems the recognizer is quite inaccurate for me.

    So I'm trying to put in some custom filters to better differentiate between the gestures, but I'm having a hard time understanding how to implement them.

    Could you give me a sample code of how it would be used, to differentiate between the "B" and "P" as you mentioned in the readme?

    Thank you!

    opened by sixpercentninja 4
  • Numbers

    Numbers

    Hey there,

    Thanks for the amazing library. I have used it in one of my apps. – Do you have a list of the "combinations" for the numbers from 0 to 9?

    Cheers, Cesare

    opened by csr 2
  • Fix broken headings in Markdown files

    Fix broken headings in Markdown files

    GitHub changed the way Markdown headings are parsed, so this change fixes it.

    See bryant1410/readmesfix for more information.

    Tackles bryant1410/readmesfix#1

    opened by bryant1410 1
  • How to set recognizer to specific view?

    How to set recognizer to specific view?

    I have modified the constraint on renderView but it still registers touches in whole viewcontroller. How to set it to register touches only within specific view.

    Thanks

    opened by nbawe 0
Owner
Didier Brun
CEO
Didier Brun
Drag gesture modifier to easily apply to any view.

SwiftUIDragModifier A description of this package. This is my first SwiftUI Package. It provides a quick way to make any SwiftUI View draggable. After

Alphonso Sensley II 0 Nov 5, 2021
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 Nov 21, 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 455 Nov 15, 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. 549 Oct 2, 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. 549 Oct 2, 2022
Handwriting numbers recognizer for Siri Remote

TvOSScribble TvOSScribble, based on CoreML, mitigates the lack of a physical numpad area in Siri Remote implementing a handwriting gesture recognizer.

David Cordero 180 Jul 6, 2022
DevTool - A simple UI and powerful Mac OS application, Such as JSON-Formatting tool, JSON-to-model tool, AppIcon generator, Network-Request tool...

?? ?? ?? A simple UI and powerful Mac OS application. It is a collection of tools commonly used in my development work. Such as JSON-Formatting tool, JSON-to-model tool, AppIcon generator, Network-Request tool...

渠晓友 3 Jul 28, 2022
PinpointKit is an open-source iOS library in Swift that lets your testers and users send feedback with annotated screenshots using a simple gesture.

PinpointKit is an open-source iOS library in Swift that lets your testers and users send feedback with annotated screenshots using a simple gesture. F

Lickability 1.1k Nov 21, 2022
Gesture Control for Safari on iOS and iPadOS

Svadilfari Svadilfari brings Gesture Control for Safari on iPhone/iPad. Features Control Safari with Gestures 10+ Customizable Actions Select Patterns

Shun Kashiwa 50 Oct 15, 2022