Hey everyone,
haven't posted here for ages, how have you guys been?
I am working on an app at the moment and I need to rotate an image.
I have found some code over at StackOverflow that does rotate my UIImageView but the problem is that once the animation is finished, the image returns to it's initial position. I don't get it. How can I make it stay where it was in the end of the animation? Because I want to be able to call the same method again afterwards and continue the rotation from where I left it last time. For example, I the image to rotate by x degrees/radians every time I call the method.
Can someone help? Here's the code I've been using (see link above)...
Code:
-(void) rotateImage {
CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat: 1.0f];
rotationAnimation.duration = 3.0;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = 1.0;
rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
[self.theImageView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}
Thanks in advance!
Cheers,
Bob