Coder Social home page Coder Social logo

kirbyt / ktonefingerrotationgesturerecognizer Goto Github PK

View Code? Open in Web Editor NEW
236.0 236.0 37.0 372 KB

KTOneFingerRotationGestureRecognizer is a custom UIGestureRecognizer for doing one finger rotations in iOS apps.

License: MIT License

Objective-C 100.00%

ktonefingerrotationgesturerecognizer's People

Contributors

kirbyt 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ktonefingerrotationgesturerecognizer's Issues

Inverted rotation at the x-axis center of the recognizer's view

Hi,

First, thanks for this rotation recognizer which is very easy to use !

I've noticed that the rotation returned by the gesture recognizer is not correct when the finger pass by the x-axis center of the view linked with the recognizer.

For instance, if I'm sliding with my finger from the upper-left corner to the upper-right corner of the view, the rotation should always be positive. Unfortunately, the rotation is inverted when the finger pass by the x-axis center of this view and therefore becomes positive.

Note that this issue does not occur when rotating the view with a CGAffineTransformRotate function call. This only occurs when the transformation matrix of the view is unchanged during the rotation.

Also note that I'm only experiencing this problem with the x-axis center and not with the y-axis center.

I'm trying to implement a circular slider with you're recognizer. It works fine, except when the slide passes by the x-axis center of the view...

Hope you got my point and you'll be able to spot the problem.

Cheers,

Damien

get the angle rotated

how would you get the angle rotated using the gesture recognizer.

i want to calculate the angle depending on the swipe gesture so that if, for example every time the user swipes 25 degrees a method is called. So if the user continues to swipe in one fluid motion 90 degrees the method is called at least three times.

Let me know if you can provide some insight on how i can do this using the one figure gesture

Thanks
Abhi

Image not appears properly when Device is Rotated

Hi,

First of all, Thanks for such nice code. It helped me a lot in one of my app.

I am facing a problem in it, if you can help for it.

If I rotate the device, the image distorted.

I have added images below. First Image is proper, while in second image you can see the small hand distorted.

1

2

Thanks

Fix for misinterpret single-tag as rotation

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    if ([self state] == UIGestureRecognizerStateChanged) {
        [self setState:UIGestureRecognizerStateEnded];
    } else {
        [self setState:UIGestureRecognizerStateFailed];
    }
}

Image not centre to the device

This piece of code is great, but I am having issues with the image when it is not placed in the centre. I don't know what I have done! Don't know if you have see the iPlayer Radio App? There is a circle that rotates down the bottom. I want to basically replicate that.

The issue is as soon as you pull the image away from the centre of the screen > run > rotate with touch the image moves towards the centre and back as you rotate the image.

Any ideas or changes would be greatly appreciated. Thank you.

Divide by zero error causes rotation to become NAN

Sometimes the Rotation Gesture recognizer returns NAN as the result of a divide by zero error. It happens here...

    CGFloat line1Slope = (line1End.y - line1Start.y) / (line1End.x - line1Start.x);
    CGFloat line2Slope = (line2End.y - line2Start.y) / (line2End.x - line2Start.x);

if either of these denominators == 0.0 the rotation property will become NAN which will probably crash whatever app it's being used for.

I fixed this fairly easily by checking for it first and not updating the rotation for that frame if it would divide by zero.

if((line1End.x - line1Start.x) == 0.0 ||  (line2End.x - line2Start.x) == 0.0)
{
    NSLog(@"KTOneFingerRotationGestureRecognizer:: Divide by zero!!!");


}else
{

    CGFloat line1Slope = (line1End.y - line1Start.y) / (line1End.x - line1Start.x);
    CGFloat line2Slope = (line2End.y - line2Start.y) / (line2End.x - line2Start.x);

    CGFloat degs = acosf(((a*c) + (b*d)) / ((sqrt(a*a + b*b)) * (sqrt(c*c + d*d))));

    CGFloat angleInRadians = (line2Slope > line1Slope) ? degs : -degs;
    //////

    [self setRotation:angleInRadians];
}

How can i translate an image after image rotation

I am able to do rotation by using single finger but when i tried to translate the images by using double that are not moving.

I am using this below code for translation but after implementation of KTOneFingerRotationGestureRecognizer code, image are not translating.

  • (void)translate:(UIPanGestureRecognizer *)gesture {
    if ((gesture.state == UIGestureRecognizerStateChanged) ||(gesture.state == UIGestureRecognizerStateEnded))
    {

    CGPoint translation = [gesture translationInView:self];
    self.transform = CGAffineTransformTranslate(self.transform, translation.x, translation.y);
    [gesture setTranslation:CGPointZero inView:self];

    }

}

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.