我在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")
此处ProgressCircle
是CAShapeLayer
。
我在下面的代码中使用动画的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)"
}
}
}
}