I'm experimenting with CAAnimation and like many new comers doing the CAAnimation; upon completion, the layer is reverted back to its original state.
The question on how to resolve this have asked few times here, and the answer is to add the following code to your CAAnimation.
animation.removedOnCompletion = NO;
While this works, but according to Apple's WWDC video discussing CAAnimation, the recommended solution would be:
// animating opacity
layer.opacity = newOpacityValue;
[layer addAnimation:animation forKey:@"opacity"];
So I'm interested to know what is the main difference between this two and when to use them?
Explicit animations do not actually modify the attributes of a CALayer.
They just modify the presentationLayer, this is what you actually see. When the animation is finished you will see the CALayer exactly the same as it was before the animation.
By setting the value like this
// animating opacity
layer.opacity = newOpacityValue;
[layer addAnimation:animation forKey:@"opacity"];
you make sure the animated values are stored in the model, so your changes will live on even when the animation is removed from the layer.
Using removedOnCompletion = YES is not a persistent solution. Whenever you remove animations from a layer it will restore to is old state.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With