【发布时间】:2015-12-30 02:50:00
【问题描述】:
我为圆创建了一个 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")
但是,这不是我想要的。我需要为圆形填充设置动画,而不仅仅是边框。谢谢。
【问题讨论】:
-
我不确定您的
strokeStart或1.0。我会不理它的。此外,您的NSNumber实例化是不必要的(例如,您可以使用0.0而不是NSNumber(float: 0.0)),因为 Swift 似乎会自动为您创建NSNumber对象...
标签: ios cocoa-touch core-graphics core-animation