I'm animating a CALayer using CABasicAnimation and expecting the layer to remain in position when the animation completes. Nearly all solutions show the following, which works fine
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
However, the 2010 WWDC speaker in the Core Animation in Practice Part 1 (~38-41mins) says that most of the solutions to the disappearing layer found are "bogus" and the correct way to animate a layer is roughly the following
animation.fromValue = [NSNumber numberWithFloat:layer.position.y];
layer.position = CGPointMake(layer.position.y, endPoint);
animation.toValue = [NSNumber numberWithFloat:endPoint];
The reason given is that the removedOnCompletion/fillMode solution only freezes the presentation layer, and the actual layer still has its original position set.
Please correct me if I've misinterpreted the speaker.
If I have understood him correctly, when does it matter?
Thanks, Steve
It depends on what you want to do... Your own explanation seems pretty clear.
If you only animate properties without changing the actual value, then "what you see" is actually different from "what is". Most of the time, you don't want that. (And when you use UIView
animations, or CALayer
implicit animations, "what is" and "what you see" are synchronized, which is consistent with the direct setter syntax).
But in some cases, it can be useful to preserve the actual value, and temporary display something different on screen... as long as you know what you're doing!
You understand it right.
It means that when you do an animation on a layer a "special" layer called "presentation layer" is created and the animation actually took place on it, but the actual layer isn't changed. In fact you MUST set the property to the layer at the end of the animation to "syncronize" the layer with the final animation status.
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