I can't find a solution online for snapping an image to an angle depending on the current angle of the image, after rotation has finished.
How do you find the angle of a view?
This is the callback method my rotation gesture uses.
The image rotates smooth, but I want the image to snap to 90, 180, 270 or 0 degrees, depending on which it is nearest to, after the user lifts their fingers off the screen.
I can't even start coding it myself because I can't find the current angle of the image view before or after rotation. My views are arranged in a xib as so:
view - > scroll view - > image view
i have tried using the tan cos sin methods to no avail. using NSLog the debug panel shows values of 0 each time. I have tried to cumulate the rotation into a variable (before recognizer.rotation is set to zero in above method) but the values are not consistent e.g. a 90 rotation will return random numbers like 2.9 or 142.0.
How do you find the angle of a view?
How do you find the angle of a view?
This is the callback method my rotation gesture uses.
Code:
-(void)rotateGestureRecognized:(UIRotationGestureRecognizer*)recognizer
{
recognizer.view.transform = CGAffineTransformRotate(recognizer.view.transform, recognizer.rotation);
recognizer.rotation = 0;
}
The image rotates smooth, but I want the image to snap to 90, 180, 270 or 0 degrees, depending on which it is nearest to, after the user lifts their fingers off the screen.
I can't even start coding it myself because I can't find the current angle of the image view before or after rotation. My views are arranged in a xib as so:
view - > scroll view - > image view
i have tried using the tan cos sin methods to no avail. using NSLog the debug panel shows values of 0 each time. I have tried to cumulate the rotation into a variable (before recognizer.rotation is set to zero in above method) but the values are not consistent e.g. a 90 rotation will return random numbers like 2.9 or 142.0.
How do you find the angle of a view?