如何让CAKeyframeAnimation在重写另一个状态时接收当前状态?

时间:2022-09-26 11:48:30

I have one like this:

我有这样一个:

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 this animation goes 3.35 seconds. In the meantime, it can happen that at i.e. 2 seconds a new animation with the same key @"theAnimation" is kicked off, for different values.

你看这个动画是3。35秒。与此同时,可能会在2秒内,为不同的值,以相同的键@“theAnimation”启动一个新的动画。

Problem what's happening: New animation does not pick up the current visible state. It begins hard from scratch. The view jumps to start position in a ugly manner and from there, the new animation begins. For UIView there is an setAnimationsBeginFromCurrentState=YES, but I haven't found anything like that for CAKeyFrameAnimation. Any idea?

问题发生了什么:新动画没有获取当前可见状态。一切都是从零开始。视图以一种丑陋的方式跳转到开始位置,从那里,新的动画开始。对于UIView有一个setAnimationsBeginFromCurrentState=YES,但是我还没有为CAKeyFrameAnimation找到类似的东西。任何想法?

1 个解决方案

#1


4  

You want to query the layer for its presentation layer, which is its current interpolated state including any animations currently running.

您希望查询层的表示层,表示层是其当前的插入状态,包括当前正在运行的任何动画。

-

- - - - - -

Excerpt from the CALayer Class Reference:

节选自CALayer的类引用:

 -(id)presentationLayer

Returns a copy of the layer containing all properties as they were at the start of the current transaction, with any active animations applied.

返回包含当前事务开始时所有属性的层的副本,并应用任何活动动画。

-

- - - - - -

The relationship of the Layer Tree (your data), the Presentation Tree (current interpolation values of your data), and the Render Tree are explained here in the CA programming guide.

层树(您的数据)、表示树(您的数据的当前插补值)和呈现树的关系在CA编程指南中进行了解释。

Core Animation Rendering Architecture

核心动画渲染架构

#1


4  

You want to query the layer for its presentation layer, which is its current interpolated state including any animations currently running.

您希望查询层的表示层,表示层是其当前的插入状态,包括当前正在运行的任何动画。

-

- - - - - -

Excerpt from the CALayer Class Reference:

节选自CALayer的类引用:

 -(id)presentationLayer

Returns a copy of the layer containing all properties as they were at the start of the current transaction, with any active animations applied.

返回包含当前事务开始时所有属性的层的副本,并应用任何活动动画。

-

- - - - - -

The relationship of the Layer Tree (your data), the Presentation Tree (current interpolation values of your data), and the Render Tree are explained here in the CA programming guide.

层树(您的数据)、表示树(您的数据的当前插补值)和呈现树的关系在CA编程指南中进行了解释。

Core Animation Rendering Architecture

核心动画渲染架构