iOS 核心动画值插值
据我所知,简单地说,核心动画实际上是通过随时间插值属性值来工作的。鉴于此,有什么方法可以将属性插值到特定时间吗?例如,我有动画,
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
可以通过将动画的 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
开源INTUAnimationEngine 库将完全满足您的需求。
它提供的 API 看起来非常类似于 UIView 上基于块的动画 API,这是最基本的变体:
重要的区别在于,您传递给 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:
The important difference is that the
animations
block you pass to INTUAnimationEngine will be executed once every frame of the animation, and thepercentage
(orprogress
) value passed into theanimations
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.
您可以将关键帧动画与核心动画一起使用。
这是一个教程
You can use keyframe animation with Core Animation.
Here is a tutoirial