如何在iOS中填充进度圈?

我需要像这样做一个进度圈: 在这里输入图像说明

我为这个圆圈创build了一个CAShapeLayer,并为它的strokeEnd属性设置了这样的animation:

pieShape = CAShapeLayer() pieShape.path = UIBezierPath(arcCenter: CGPointMake(29, 29), radius: 27.0, startAngle: CGFloat(startAngle), endAngle: CGFloat(endAngle), clockwise: true).CGPath pieShape.fillColor = UIColor.clearColor().CGColor pieShape.strokeColor = UIColor.blackColor().CGColor pieShape.lineWidth = 4.0 self.layer.addSublayer(pieShape) let countDownAnimation = CABasicAnimation(keyPath: "strokeEnd") countDownAnimation.duration = durationInSeconds countDownAnimation.removedOnCompletion = false countDownAnimation.fromValue = NSNumber(float: 0.0) countDownAnimation.toValue = NSNumber(float: 1.0) countDownAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear) self.pieShape.strokeStart = 1.0 self.pieShape.addAnimation(countDownAnimation, forKey: "drawCircleAnimation") 

但是,这不是我想要的。 我需要animation圈填充,不仅是边界。 谢谢。

最简单的方法就是作弊,使中风animation,但似乎是animation填充的圆圈。 例如,如果您想要一个半径为30的圆,请使用radius15而不是30lineWidth ,以便笔划有效地覆盖从中心到所需的半径30

在这里输入图像说明

有更复杂的方法使用CADisplayLink ,并自己更新,但上述是很容易达到预期效果的方法。