手动控制UIView动画的进度,而不是在持续时间内自动控制 [英] Control a UIView animation's progress manually instead of automatically through the time duration

查看:253
本文介绍了手动控制UIView动画的进度,而不是在持续时间内自动控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置一个UIView动画,但是我花了一段时间来控制百分比进度,让它自动为我插值。那可能吗?谢谢

I want to setup a UIView animation, but instead of it taking a given amount of time, i want to control the percentage progress and let it automatically interpolate the values for me. Is that possible? Thanks

推荐答案

我想我已经知道了。在[UIView animate ...]块之后,立即在根视图上执行以下操作:

I think i've got it. Immediately after the [UIView animate...] block, do the following on the root view:

_view.layer.speed = 0.0;
_view.layer.timeOffset = [_view.layer convertTime:CACurrentMediaTime() fromLayer:nil];

要设置比例点,请执行:

And to set the point on the scale, do:

_view.layer.timeOffset = 0..1; (where 1 is the same value as the original duration)

要恢复,类似于以下内容:

And to resume, something similar to the following:

CALayer *layer = _view.layer;
CFTimeInterval pausedTime = [layer timeOffset];
layer.speed = 1.0;
layer.timeOffset = 0.0;
layer.beginTime = 0.0;
CFTimeInterval timeSincePause = [layer convertTime:CACurrentMediaTime() fromLayer:nil] - pausedTime;
layer.beginTime = timeSincePause;

这一切都来自: https://developer.apple.com/library/ios/qa/qa1673/_index.html

这篇关于手动控制UIView动画的进度,而不是在持续时间内自动控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆