我不是 100% 确定这是否适合作为一个编程问题,因为这主要是一个我很难解决的数学逻辑问题,所以如果不是我的错的话。
我正在使用下面的一些代码来制作一个圆圈动画:
// 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 秒内被填充。
我知道如何获取时间戳,我知道如何获取时间戳距离当前时间有多少秒,但我不知道如何计算出中风开始。
对此有什么想法吗?
最佳答案
由于一圈是 240 秒,并且您知道已经过去了多少秒,因此只需除以即可。
let strokeStart = Double(secondsElapsed) / 240.0
关于ios - 根据时间戳计算动画中风开始?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41071709/