I'm trying to animate the scale then the opacity of a CALayer
, like so:
CABasicAnimation *scaleUp = [CABasicAnimation animationWithKeyPath:@"transform"];
scaleUp.fromValue = [NSValue valueWithCATransform3D:self.timerProgressLayer.transform];
scaleUp.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)];
scaleUp.duration = 0.25;
scaleUp.fillMode = kCAFillModeForwards;
CABasicAnimation *fadeOut = [CABasicAnimation animationWithKeyPath:@"opacity"];
fadeOut.fromValue = @(1.0);
fadeOut.toValue = @(0.0);
fadeOut.beginTime = 0.3;
fadeOut.duration = 0.25;
fadeOut.fillMode = kCAFillModeForwards;
CAAnimationGroup *group = [CAAnimationGroup animation];
group.animations = @[scaleUp, fadeOut];
group.removedOnCompletion = YES;
group.duration = fadeOut.beginTime + fadeOut.duration;
[self.timerProgressLayer addAnimation:group forKey:@"trigger"];
That's simple enough, and the animation itself works fine. However, at the end of the animation it's removed and the values revert to the ones at the beginning. To combat this, I set the properties manually, immediately after the addAnimation:
call:
self.timerProgressLayer.opacity = 0.0;
self.timerProgressLayer.transform = CATransform3DMakeScale(1.0, 1.0, 1.0);
However, these calls override my animation, and the layer fades out and scales immediately. If I use the animation's delegate
or [CATransaction setCompletionBlock:]
to set the properties at the end of the animation, a lot of the time (but not 100% of the time), a single frame of the old state gets through between the end of the animation and the properties being set.
How can I use CAAnimationGroup
to animate some properties, removing the animation at the end without the old values peeking through for a frame?