我为圆圈创建了一个CAShapeLayer,并为其strokeEnd属性设置了这样的动画:
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")
但是,这不是我想要的。我需要为圆形填充动画,而不仅仅是边框。谢谢。