I have a CALayer object. In viewDidLoad: I set a transform to it using layer.transform = CATransform3DRotate(CATransform3DIdentity, M_PI/8.0, 0, 0, 1); This works.
After loading, I apply a CAKeyframeAnimation to animate the rotation of that layer. It also works and animation finishes correctly. To prevent the layer from removing the animation after completion I use
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
All of this works fine. But a problem occurs when I try to change the transform again (without animation) layer.transform = CATransform3DRotate(CATransform3DIdentity, M_PI/8.0, 0, 0, 1);. Nothing happens. Layer doesn’t change its transform to what I have specified. If I run the animation again, the animation will happen. But cannot change the transform property without animation.
Any help is appreciated..
OK, I managed to get this working.
What I did was setting the
layer.tranformjust after calling[layer addAnimation:]. In that way, after the animation is finished, the layer will stay in the desired position as it is. Here is my code:The problem I had was using
layer.removedOnCompletionandlayer.fillemode. I don’t have to use them. In the new way the layer will display the layer using thelayer.transformafter animation is complete.CAAnimationsonly update the layer’s presentationLayer (which maintains the layer’s visual state) while animating. When the animation is finished, it will revert the layer’s visual state to the one imposed bylayer.transform.