Correct way to prevent disappearing layer in CABasicAnimation?
cabasicanimation, objective-c
Solution
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!
Problem
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