将笔画动画设置为0仍显示较小的笔画片段

时间:2019-07-10 09:56:00

标签: ios swift cashapelayer

我正在尝试将笔划动画成一个圆。当我点击一个按钮时,笔画百分比会增加或减少。一切正常,但是当我尝试为strokeEnd制作动画时,0仍然显示一小段。

enter image description here

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
}

上面的代码。任何想法出什么问题了吗?我已经检查了日志fromValuetoValue,而toValue确实为零,但是仍然显示一个段。任何对此的指点将不胜感激。谢谢!

0 个答案:

没有答案