根据时间戳计算动画Strokestart



我不是100%确定这适用于stackoverflow作为编程问题,因为这主要是我遇到的数学逻辑问题,所以如果不是我的不好,则

我正在用下面的一些代码来动画圆圈:

// Set the animation duration appropriately
    animation.duration = duration
    // Animate from 0 (no circle) to 1 (full circle)
    animation.fromValue = strokeStart
    animation.toValue = 1
    // Do a linear animation (i.e. the speed of the animation stays the same)
    animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
    // Set the circleLayer's strokeEnd property to 1.0 now so that it's the
    // right value when the animation ends.
    progressCircle.strokeEnd = 1.0

因此,与之使用的钥匙值是持续时间,来自值,最终值始终为1。

圆的总360度始终代表240秒的时间(4分钟)。

我设置了一个函数,以插入持续时间的值并在创建圆圈时启动值,但是我很难适当地计算这些函数。

因此,例如,当我绘制其中一个圆圈时,我会从服务器上抓取时间戳。假设抓取时间戳恰好是120秒。圆应以1/2的方式绘制,其余180度应在总4分钟的其余120秒内绘制。另一个例子是,如果在3分50秒前完成了时间戳,则基本上将通过将Strokestart设置为高百分比,并且在接下来的10秒内将圆圈立即填充。

我知道如何抓取时间戳,我知道如何抓取当前时间的时间戳是多少秒,但我不知道如何计算strokestart。

对此有什么想法?

由于圆圈为240秒,您知道已经经过了多少秒,只需分割。

let strokeStart = Double(secondsElapsed) / 240.0

最新更新