I have an UIImageView with the image of a face, then I apply a rotation transform animation to that UIImageView.
self.transform = CGAffineTransformRotate(self.transform, M_PI / 16);
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionRepeat|UIViewAnimationOptionAutoreverse
animations:^{
self.transform = CGAffineTransformRotate(self.transform, -1 * (M_PI/8));
}
completion:^(BOOL completed) {}];
Then I have another animation for the same face image that moves up and down on y axis.
[UIView animateWithDuration:0.2
delay:0.0
options:UIViewAnimationOptionRepeat|UIViewAnimationOptionAutoreverse
animations:^{
self.transform = CGAffineTransformMakeTranslation(0, 10);
}
completion:^(BOOL completed){}];
After I execute the first animation I need to change UIImageView position and then start the second animation.
I have a stopAnimation method that remove animations, reset the transform, and set the position of the UIImageView.
-(void)stopAnimation:(NSInteger)currentAnimation{
[self.layer removeAllAnimations];
[self setTransform:CGAffineTransformIdentity];
[self setFrame:initFrame];
CGPoint position = [self getNextPosition:currentAnimation];
//[self setTransform:CGAffineTransformMakeTranslation(0, 0)];
CGRect frame = self.frame;
frame.origin.x = position.x;
frame.origin.y = position.y;
self.frame = frame;
}
-(CGPoint)getNextPosition:(NSInteger)currentAnimation{
CGPoint position = [[positions objectAtIndex:(currentAnimation-1)] CGPointValue];
NSLog(@"Current animation:%u %f:%f", currentAnimation,position.x,position.y);
return position;
}
If I execute the change of position without the animations the UIImageView are in the correct position of the screen but if I run with the animation, the animations work good but the UIImageView position is wrong.
I tried the same setting the center of the UIImageView but I have same problem.