我很难理解为什么动画不能像预期的那样工作.我在做什么是这样的:
UIBezierPath使用圆弧创建一个沿此路径移动Label并为路径描边设置动画.
//Start Point is -.pi /2 to let the Arc start at the top.
//self.progress = Value between 0.0 and 1.0
let path : UIBezierPath = UIBezierPath.init(arcCenter: CGPoint.init(x: self.bounds.width * 0.5, y: self.bounds.height * 0.5),
radius: self.bounds.width * 0.5, startAngle: -.pi / 2, endAngle: (2 * self.progress * .pi) - (.pi / 2), clockwise: true)
return path
Run Code Online (Sandbox Code Playgroud)将此路径添加到 CAShapeLayer
circlePathLayer.frame = bounds
circlePathLayer.path = self.path.cgPath
circlePathLayer.strokeStart = 0
circlePathLayer.strokeEnd = 1
Run Code Online (Sandbox Code Playgroud)使用a为strokeEnd属性设置动画 CABasicAnimation
let animation = CABasicAnimation(keyPath: "strokeEnd") …Run Code Online (Sandbox Code Playgroud)