Smooth update of layer visual property values ​​after completion of `CAAnimationGroup`?

I try to animate the scale and then the opacity CALayer, for example:

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"];

It's simple enough, and the animation itself works great. However, at the end of the animation, it is deleted, and the values ​​return to the values ​​at the beginning. To combat this, I set the properties manually right after the call addAnimation::

self.timerProgressLayer.opacity = 0.0;
self.timerProgressLayer.transform = CATransform3DMakeScale(1.0, 1.0, 1.0);

However, these calls override my animation, and the layer gradually fades and scales. If I use animation delegateor [CATransaction setCompletionBlock:]to set properties at the end of the animation, a lot of time (but not 100% of the time), one frame of the old state passes between the ends of the animation and the properties being set.

CAAnimationGroup , , ?

+4
1

. .

, , . , .


" ". - , , :

[CATransaction begin];
[CATransaction setDisableActions:YES]; // actions are disabled for now

self.timerProgressLayer.opacity = 0.0;
self.timerProgressLayer.transform = CATransform3DMakeScale(1.0, 1.0, 1.0);

[CATransaction commit];                // until here
+3

All Articles