如何让 CAKeyframeAnimation 在覆盖另一个 CAKeyframeAnimation 时获取当前状态?

发布于 2024-08-02 20:36:06 字数 714 浏览 4 评论 0原文

我有一个这样的:

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

你看这个动画持续 3.35 秒。与此同时,可能会发生这样的情况:即 2 秒时,会针对不同的值启动具有相同键 @“theAnimation”的新动画。

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

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.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

演多会厌 2024-08-09 20:36:06

您想要查询图层的表示层,这是其当前的插值状态,包括当前正在运行的任何动画。

-

摘自 CALayer 类参考:

 -(id)presentationLayer

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

-

CA 编程指南中解释了图层树(您的数据)、表示树(数据的当前插值)和渲染树之间的关系。

核心动画渲染架构

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:

 -(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.

Core Animation Rendering Architecture

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文