【发布时间】:2020-03-28 19:45:58
【问题描述】:
我这样定义了一个圆圈:
let progressLayer = CAShapeLayer()
let ring = UIBezierPath(arcCenter: center, radius: 100, startAngle: -CGFloat.pi / 2 , endAngle: 2 * CGFloat.pi , clockwise: true)
progressLayer.path = ring.cgPath
progressLayer.strokeColor = UIColor.green.cgColor
progressLayer.fillColor = UIColor.clear.cgColor
view.layer.addSublayer(progressLayer)
然后我定义了一个动画,用这样的颜色和持续时间填充我的圆圈的边框:
let basicAnimation = CABasicAnimation(keyPath: "strokeEnd")
basicAnimation.toValue = 1
basicAnimation.duration = 60 //Seconds !
basicAnimation.fillMode = .forwards
progressLayer.add(basicAnimation, forKey: "blablabla")
发生的情况是动画延迟了 12 秒到达了循环的尽头! (圆圈已填满,但还剩 12 秒) 为什么会这样?是三角问题(startAngle endAngle)吗?看不懂……
【问题讨论】:
标签: ios swift xcode geometry cabasicanimation