I an trying to animate a UIImageView
to rotate counter clockwise when a user touches it and moves its finger on it in clockwise direction.
Basically I want the UIImageView to go back to its original position once the touch ends and it should move in counter clockwise direction.
The problem I have is that every time angle (in degrees) is greater than 180 then the image rotates clockwise back to its original position. Its apparently taking the shortest path back. As for angles 179 degrees or less the image rotate counter clockwise (what i need).
I tried both these pieces of code and they behave the same way. Any suggestions?
NOTE: here angle variable is a double and its initialized to be zero and it remains 0 throughout my code
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[self handleObject:touches withEvent:event isLast:YES];
/* this doesn't make rotation counter clockwise for rotations greater than 180 */
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve: UIViewAnimationCurveLinear];
[UIView setAnimationDuration:1.0];
[UIView setAnimationRepeatCount:1];
CGAffineTransform transform = CGAffineTransformMakeRotation(angle);
circle1ImgVw.transform = CGAffineTransformRotate(transform, angle);
// ends animation
[UIView commitAnimations];
/* this doesn't make rotation counter clockwise for rotations greater than 180 */
[UIView animateWithDuration:1.0 animations:^{
circle1ImgVw.transform = CGAffineTransformMakeRotation(angle);
}];
}
I tried looking into this post and there are couple of problems with it
- I cannot touch and rotate the image anymore after the animation is done
- It always animates in clockwise direction and I haven't been able to figure out how to make it go counter clockwise smoothly from the point where the user ended rotating the image.