Giter VIP home page Giter VIP logo

pennypincher's Introduction

Carthage compatible License Platform Swift

PennyPincher

Penny Pincher is a fast template-based gesture recognizer, developed by Eugene Taranta and Joseph LaViola (full paper reference below). The algorithm is well-suited for mobile applications since it is both fast and accurate and, as shown in the evaluation by the authors, outperforms other recognizers. This project provides a Swift implementation of Penny Pincher and shows its usage in a simple example project. Also, the framework contains a UIGestureRecognizer subclass that integrates well into the existing gesture recognition framework of iOS.

Here's the full reference for the paper:

Eugene M. Taranta, II and Joseph J. LaViola, Jr.. 2015. Penny pincher: a blazing fast, highly accurate $-family recognizer. In Proceedings of the 41st Graphics Interface Conference (GI '15). Canadian Information Processing Society, Toronto, Ont., Canada, Canada, 195-202.

Demo

PennyPincher

Requirements

v1.1.0: >= iOS 9, Xcode 8, Swift 3.0
v1.0.3: >= iOS 8, Xcode 7, Swift 2.0

Installation

Recommended installation options are via Carthage or manual installation.

Carthage:

PennyPincher supports installation via Carthage:

  • Add the following line to your Cartfile: github "fe9lix/PennyPincher" >= 1.1
  • Run carthage update

Manual:

  • Drag the folder PennyPincherExample/Carthage/Build/iOS/PennyPincher.framework into your Xcode project and select "Copy items if needed".
  • Make sure that the framework is added under Embedded Binaries in the general section of your project's target settings.

Usage

Please see the ViewController of the example project on how to use PennyPincher. Although you can use the PennyPincher class directly, the easiest way is to instantiate its gesture recognizer class, configure it, and add it to a view:

let pennyPincherGestureRecognizer = PennyPincherGestureRecognizer()
pennyPincherGestureRecognizer.enableMultipleStrokes = true
pennyPincherGestureRecognizer.allowedTimeBetweenMultipleStrokes = 0.2
pennyPincherGestureRecognizer.cancelsTouchesInView = false
pennyPincherGestureRecognizer.addTarget(self, action: "didRecognize:")

view.addGestureRecognizer(pennyPincherGestureRecognizer)

In the code above, the following properties are set:

  • enableMultipleStrokes: Allows gestures to be composed of multiple separate strokes, as long as the pause between strokes does not exceed allowedTimeBetweenMultipleStrokes. When the property is set to false, the gesture recognizer transitions to the cancelled state as soon as the user lifts the finger.
  • allowedTimeBetweenMultipleStrokes: See above.
  • cancelsTouchesInView: Regular iOS gesture recongizer property. Might be set to false when you want to ensure that touches are still delivered to the attached view.

The target-action pair is executed for state changes triggered by the recognizer. You can use the state property to react accordingly in the UI. The result property returns a tuple consisting of the recognized PennyPincherTemplate and CGFloat value indicating the similarity. For example:

guard let (template, similarity) = pennyPincherGestureRecognizer.result else {
    print("Could not recognize.")
    return
}

let similarityString = String(format: "%.2f", similarity)
print("Template: \(template.id), Similarity: \(similarityString)")

You can add and remove templates by modifying the templates array property of the recognizer. The PennyPincher class provides a static method to create new templates of type PennyPincherTemplate (a struct). Required parameters are the id (a unique string) and points (an array of CGPoints).

For example:

let template = PennyPincher.createTemplate("templateID", points: points)
pennyPincherGestureRecognizer.templates.append(template)

Templates could be serialized and saved to disk and then loaded again into memory when the application launches. PennyPincher works pretty well with only one template per gesture (id) but, depending on your use case, you can increase its accuracy by adding more for each gesture.

Author

fe9lix

License

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

pennypincher's People

Contributors

fe9lix avatar rmtheis avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.