CATransform3DRotate and UIImageView

I am animating a UIImage with this code

 CABasicAnimation *animation; animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; animation.duration = 1; animation.toValue = [NSNumber numberWithFloat:M_PI]; animation.fromValue = [NSNumber numberWithInt:0]; [square.layer addAnimation:animation forKey:@"rotation"]; 

Everything works fine, but my array takes its original position at the end of the animation. I looked at the properties of the layer and found:

 [square.layer setTransform:CATransform3DRotate(HERE, -M_PI, 0, 0, 0)]; 

And I do not know what to write instead of "HERE". Could you help me please? Many thanks!

+7
iphone core-animation
source share
1 answer

CATransform3DRotate() takes a transformation as its first parameter to apply rotation to. If you want to rotate the transformation of your layer, you should use

 [square.layer setTransform:CATransform3DRotate(square.layer.transform, -M_PI, 0, 0, 0)]; 

However, if the problem you are facing is that the layer returns to its original position at the end of the animation, all you have to do is set the removedOnCompletion animation removedOnCompletion to NO and its fillMode property is kCAFillModeForwards .

+3
source share

All Articles