The rotation gesture works. The image rotates fine. But I'm trying to find out how much the image rotates by recording some sort of linear change in some value. I'm failing. Can anyone help?
The NSLog statements below generate random numbers that I can't explain. Am I on the right track here? Has anyone found a solution to this?
The NSLog statements below generate random numbers that I can't explain. Am I on the right track here? Has anyone found a solution to this?
Code:
-(void)rotationGestureRecognized:(UIRotationGestureRecognizer*)recognizer
{
if (recognizer.state == UIGestureRecognizerStateBegan) {
lastRotation = recognizer.rotation;
}
if (recognizer.state == UIGestureRecognizerStateBegan || recognizer.state == UIGestureRecognizerStateChanged)
{
CGFloat newRotation = 1 - (lastRotation - recognizer.rotation);
if (newRotation < 1)
{
//Clockwise
CGFloat rotation = 1 - newRotation;
totalClockwiseRotation += rotation;
totalAntiClockwiseRotation += rotation;
} else if (newRotation >= 1)
{
//Anti-Clockwise
CGFloat rotation = newRotation - 1;
totalAntiClockwiseRotation -= rotation;
totalClockwiseRotation -= rotation;
}
//Perform Rotation
CGAffineTransform transform = CGAffineTransformRotate(recognizer.view.transform, recognizer.rotation);
recognizer.view.transform = transform;
recognizer.rotation = 0;
}
if (recognizer.state == UIGestureRecognizerStateEnded)
{
if (totalAntiClockwiseRotation > 0) totalClockwiseRotation = 0;
if (totalClockwiseRotation < 0) totalAntiClockwiseRotation = 0;
NSLog(@"totalAntiClockwiseRotation: %f", totalAntiClockwiseRotation);
NSLog(@"totalClockwiseRotation: %f", totalClockwiseRotation);
}
}
Last edited: