GithubHelp home page GithubHelp logo

michmich / xmcirclegesturerecognizer Goto Github PK

View Code? Open in Web Editor NEW
77.0 4.0 12.0 1.02 MB

An one finger circle gesture recognizer in swift.

Home Page: http://michaelteeuw.nl/post/90182386142/swift-around-and-around

License: Apache License 2.0

Swift 100.00%

xmcirclegesturerecognizer's Introduction

XMCircleGestureRecognizer

XMCircleGestureRecognizer was written by Michael Teeuw

What is it?

An one finger circle gesture recognizer written in swift.

How to use

Add a XMCircleGestureRecognizer recognizer to your view

let cgr = XMCircleGestureRecognizer(midPoint: self.view.center, innerRadius:10, outerRadius:200, target: self, action: "rotateGesture:"))
view.addGestureRecognizer(cgr)

Or, of you don't need a minimum and maximum distance to your center point:

let cgr = XMCircleGestureRecognizer(midPoint: self.view.center, target: self, action: "rotateGesture:"))
view.addGestureRecognizer(cgr)

Add a gesture responder function to your target to respond to the gesture:

func rotateGesture(recognizer:XMCircleGestureRecognizer)
{
    if let rotation = recognizer.rotation {
        // rotation is the relative rotation for the current gesture in radians
    }
    
    if let angle = recognizer.angle {
        // angle is the absolute angle for the current gesture in radians
    }
    
    if let distance = recognizer.distance {
        // distance is the absolute distance from the midPoint
    }
}

If you like to transform the values from radians to degrees, simply add .degrees to the variable:

if let rotation = recognizer.rotation {
    // rotation.degrees is the relative rotation for the current gesture in degrees
}

So what does it look like?

Disclaimer

This is my fist open source Swift class. So be gentle. ;)

Contributing

Forks, patches and other feedback are welcome.

xmcirclegesturerecognizer's People

Contributors

davidebettio avatar michmich avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

xmcirclegesturerecognizer's Issues

Possible to Overlay a Tap Recognizer?

Loving this and it's working great so far! Thank you MichMich!

Just one challenge - I have tried to add a Tap Gesture Recognizer on top but it does not get recognized.

I have also tried to add a Button, and it also does not get recognized.

Any tips on how to workaround either of these?

How can I escape from the recognizer ?

Hi,

First of all, thank you for your work, it works amazingly.
I'm building an app where I'd like to recognize a lot of different gesture (such as tap, tap with multiple fingers, swipes, long press, but without using apple gesture recognizer that are too accurate (That's ironic right ?).

Anyway I'd like to use your class but I've a problem: I can't release the XMCircleRecognizer. So, when I enter in it after some conditions, I can't escape, so I can't recognize another gesture after.

Do you have an Idea how I could handle this problem ? I thought of a kind of :

let rotationRecognizer = self.view.addGestureRecognizer(XMCircleGestureRecognizer(midPoint: self.view.center, target: self, action: #selector(ViewController.rotateGesture(recognizer:))))
rotationRecognizer.enabled = false (or true)

As I'm pretty new to swift, I've no idea how I could do that.

Once again, thanks for you amazing work.

Handling multitouch

Hei.
Just asking... shouldn't you work only with first touch? You're using touches.anyObject() everywhere, but what will happen when user touches with more than one finger?

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.