使用swift中的CABasicAnimation进行动画标签计数?

时间:2017-11-16 07:17:49

标签: ios swift animation

我在CABasicAnimation上添加了CAShapeLayer。现在在这个动画中我的CAShapeLayer在带有动画的圆上创建一个圆弧。

现在,当这个动画进行标签计数时,我想要的是同步到CAShapeLayer的动画。请问我该怎么办?

let animation = CABasicAnimation(keyPath: "strokeEnd")
//animation.delegate = self
animation.duration = 2
animation.fromValue = 0
animation.toValue = 0.7 // changed here
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
animation.isRemovedOnCompletion = false

progressCircle.add(animation, forKey: "ani")

此处ProgressCircleCAShapeLayer

我在下面的代码中使用动画的increement标签计数,但它与动画不匹配。

func incrementLabel(to endValue: Int) {
        let duration: Double = 1.0 //seconds
        DispatchQueue.global().async {
            for i in 0 ..< (endValue + 1) {
                let sleepTime = UInt32(duration/Double(endValue) * 1000000.0)
                usleep(sleepTime)
                DispatchQueue.main.async {
                    self.label.text = "\(i)"
                }
            }
        }
    }

0 个答案:

没有答案