How to let CAKeyframeAnimation pick up the current state when overriding another?

I have one such:

CALayer *layer = stripeButton.layer;
CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:@"bounds.origin.y"];
moveAnim.duration = 3.35;
moveAnim.repeatCount = 0;
moveAnim.autoreverses = NO;
moveAnim.removedOnCompletion = NO;
moveAnim.calculationMode = kCAAnimationLinear;
moveAnim.fillMode = kCAFillModeForwards;

// ... keys and values here ...

[theLayer addAnimation:moveAnim forKey:@"theAnimation"];

You see that this animation lasts 3.35 seconds. Meanwhile, it may happen that after 2 seconds a new animation with the same key @ "theAnimation" will be launched for different values.

The problem is what happens: the new animation does not display the current visible state. It starts from scratch. The view goes to its original position in an ugly manner, and from there a new animation begins. For UIView, there is setAnimationsBeginFromCurrentState = YES, but I did not find anything similar for CAKeyFrameAnimation. Any idea?

+3
source share
1 answer

, , .

-

CALayer:

 -(id)presentationLayer

, , , .

-

( ), ( ) .

Core Animation

+4

Source: https://habr.com/ru/post/1715816/


All Articles