我正在尝试将笔划动画成一个圆。当我点击一个按钮时,笔画百分比会增加或减少。一切正常,但是当我尝试为strokeEnd
制作动画时,0
仍然显示一小段。
func animate(progressPercent: Int, labelText: String, delay: TimeInterval = 0.0, duration: TimeInterval =
Constants.duration) {
label.text = labelText
let animateStroke = CABasicAnimation(keyPath: "strokeEnd")
animateStroke.fromValue = fromValue
let toValue: Double = progressPercent == 0 ? 0 : Double(progressPercent) / 100.0
animateStroke.toValue = toValue
animateStroke.duration = duration
animateStroke.fillMode = .both
animateStroke.isRemovedOnCompletion = toValue == 0
animateStroke.beginTime = CACurrentMediaTime() + delay
circleProgressLayer.add(animateStroke, forKey: "MyAnimation")
print("from value is \(fromValue) to value is \(toValue)")
fromValue = toValue
}
上面的代码。任何想法出什么问题了吗?我已经检查了日志fromValue
和toValue
,而toValue
确实为零,但是仍然显示一个段。任何对此的指点将不胜感激。谢谢!