When you add animation to a layer, the animation does not change the properties of the layer. Instead, the system creates a copy of the layer. The initial layer is called the model layer, and the duplicate is called the presentation layer. The properties of the presentation layer change as the animation progresses, but the properties of the model layer remain unchanged.
When you remove an animation, the system destroys the presentation layer, leaving only the model layer, and then the model layer properties control how the layer is drawn. Therefore, if the properties of the model layer do not correspond to the final animated values โโof the properties of the view layer, the layer will be instantly reset until it appears before the animation.
To fix this, you need to set the model layer properties to the final animation values, and then add the animation to the layer. You want to do this in this order, because changing a layer property can add implicit animation to the property, which contradicts the animation you want to explicitly add. You want your explicit animation to overlap the implicit animation.
So how do you do all this? The basic recipe is as follows:
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"]; animation.fromValue = [NSValue valueWithCGPoint:myLayer.position]; layer.position = newPosition;
I did not use an animation group, so I do not know exactly what you need to change. I just add each animation separately to the layer.
Itโs also easier for me to use the +[CATransaction setCompletionBlock:] method to set a completion handler for one or more animations instead of trying to use an animation delegate. You install the transaction completion block, then add the animation:
[CATransaction begin]; { [CATransaction setCompletionBlock:^{ [self.imageView removeFromSuperview]; }]; [self addPositionAnimation]; [self addScaleAnimation]; [self addOpacityAnimation]; } [CATransaction commit];
rob mayoff Jul 17 '12 at 3:45 2012-07-17 03:45
source share