kirbyt / ktonefingerrotationgesturerecognizer Goto Github PK
View Code? Open in Web Editor NEWKTOneFingerRotationGestureRecognizer is a custom UIGestureRecognizer for doing one finger rotations in iOS apps.
License: MIT License
KTOneFingerRotationGestureRecognizer is a custom UIGestureRecognizer for doing one finger rotations in iOS apps.
License: MIT License
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.
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];
}
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
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
if ([self state] == UIGestureRecognizerStateChanged) {
[self setState:UIGestureRecognizerStateEnded];
} else {
[self setState:UIGestureRecognizerStateFailed];
}
}
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];
}
}
I'm just curious if you think it would be possible to make this work in conjunction with a pan gesture recognizer. So, dragging on the edge rotates, but dragging in the center of a view will instead pan the view.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.