I have a telephone wheel. On the touchend, it goes to his position with an animation.
Until the angle is less than 180°, it returns clockwise. No problem, with this code :
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { [UIView setAnimationBeginsFromCurrentState:YES]; [UIView beginAnimations:nil context:NULL]; [UIViewsetAnimationDuration:0.5]; wheel.transform = CGAffineTransformIdentity; [UIView commitAnimations]; }
But It goes wrong after that and continue to rotate for a complet turn.
I tried to make to animations like this :
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { [UIView setAnimationBeginsFromCurrentState:YES]; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.2]; wheel.transform = CGAffineTransformRotate(wheel.transform, degreesToRadians(-130)); [UIView commitAnimations]; [self performSelector:@selector(animatewheelViewToCenter) withObject:nil afterDelay:0.3]; } - (void)animatewheelViewToCenter{ [UIView setAnimationBeginsFromCurrentState:YES]; [UIView beginAnimations:nil context:NULL]; [UIViewsetAnimationDuration:0.3]; wheel.transform = CGAffineTransformIdentity; [UIView commitAnimations]; }
It works, but the animation isn't fluid ; the change is visible.