iOS 核心动画值插值

发布于 2024-12-27 12:53:18 字数 394 浏览 2 评论 0原文

据我所知,简单地说,核心动画实际上是通过随时间插值属性值来工作的。鉴于此,有什么方法可以将属性插值到特定时间吗?例如,我有动画,

animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
animation.duration = 1.0;
animation.fromValue = [NSNumber numberWithFloat:0.0];
animation.toValue = [NSNumber numberWithFloat:1.0];

当不透明度值也是 0.5 时,有没有办法将图层冻结在 0.5 秒?

如果没有办法用核心动画来做到这一点,是否有任何用于 Objective-C 的补间库可以实现这一点?

As I know, putting it simply, Core Animation actually works by interpolating property value over time. Given this, is there any way to interpolate the property to a specific time? For example I have animation

animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
animation.duration = 1.0;
animation.fromValue = [NSNumber numberWithFloat:0.0];
animation.toValue = [NSNumber numberWithFloat:1.0];

Is there a way to freeze the layer at, say, 0.5 seconds when the opacity value is also 0.5?

If there's no way to do it with Core Animation, are there any tweening library for objective-c that allows this?

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

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

发布评论

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

评论(3

平定天下 2025-01-03 12:53:18

可以通过将动画的 speed 属性设置为 0 来冻结动画。也可以冻结动画,然后更改其 beginTime 属性或 timeOffset 属性。

关于这两个属性的文档非常糟糕。查看此链接以获取更多信息:

时间扭曲动画

It is possible to freeze an animation by setting it's speed property to 0. It might be possible to freeze an animation, and then change it's beginTime property or timeOffset property.

The docs on both these properties is really bad. Check out this link for better information:

Time warp animation

飘逸的'云 2025-01-03 12:53:18

开源INTUAnimationEngine 库将完全满足您的需求。

它提供的 API 看起来非常类似于 UIView 上基于块的动画 API,这是最基本的变体:

// INTUAnimationEngine.h

// ...

+ (INTUAnimationID)animateWithDuration:(NSTimeInterval)duration
                                 delay:(NSTimeInterval)delay
                            animations:(void (^)(CGFloat percentage))animations
                            completion:(void (^)(BOOL finished))completion;

// ...

重要的区别在于,您传递给 INTUAnimationEngine 的 animations 块将在每一帧执行一次。动画,以及每次传递到 animations 块的百分比(或进度)值反映了动画的当前状态。

因此,您可以轻松地使用它来执行任何自定义插值、补间或您需要执行的其他逻辑。

The open source INTUAnimationEngine library will do exactly what you want.

It provides an API that looks very much like the block-based animation API on UIView, here's the most basic variant:

// INTUAnimationEngine.h

// ...

+ (INTUAnimationID)animateWithDuration:(NSTimeInterval)duration
                                 delay:(NSTimeInterval)delay
                            animations:(void (^)(CGFloat percentage))animations
                            completion:(void (^)(BOOL finished))completion;

// ...

The important difference is that the animations block you pass to INTUAnimationEngine will be executed once every frame of the animation, and the percentage (or progress) value passed into the animations block each time reflects the current state of the animation.

So you can easily use this to do whatever custom interpolation, tweening, or other logic you need to do.

赢得她心 2025-01-03 12:53:18

您可以将关键帧动画与核心动画一起使用。

这是一个教程

You can use keyframe animation with Core Animation.

Here is a tutoirial

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