首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >变速CABasicAnimation进展

变速CABasicAnimation进展
EN

Stack Overflow用户
提问于 2015-11-01 15:00:02
回答 1查看 1.2K关注 0票数 1

为了更新进度视图,我需要一次计算CABasicAnimation的进度。

当进度是线性的时,我只计算每次经过的时间(多亏了https://stackoverflow.com/a/20993376/2268168)。

问题是,动画不是线性的,速度是可变的。

加速

代码语言:javascript
复制
mylayer.timeOffset = [mylayer convertTime:CACurrentMediaTime() fromLayer:nil];
mylayer.beginTime = CACurrentMediaTime();
mylayer.speed=2;
speed = 2;

慢点

代码语言:javascript
复制
mylayer.timeOffset = [mylayer convertTime:CACurrentMediaTime() fromLayer:nil];
mylayer.beginTime = CACurrentMediaTime();
mylayer.speed=0.5;
speed = 0.5;

如何在考虑速度变化的情况下计算动画的进度?

我试过这个,但它似乎只有在速度增加一次时才起作用。

代码语言:javascript
复制
CFTimeInterval elapsedTime = (CACurrentMediaTime() - animation.beginTime);

CFTimeInterval remainingTime = (totalDuration - elapsedTime)/speed;
speed = 1;
totalDuration = remainingTime+elapsedTime;

float progress = (totalDuration-remainingTime)/totalDuration;

我做错什么了吗?

谢谢你的帮忙!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-11-01 19:41:05

感谢@danh告诉我这个答案,Core animation progress callback

这对我有帮助。

我添加了子类CALayer,它的动画方式与我的图层一样(以相同的速度变化)。这样,我就可以得到主要动画的进展。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33463551

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档