我正在创建一个随机的
问题是,一旦动画完成,阴影就会应用于整个形状。我希望阴影只应用于
以下是我所指的问题示例:
UIBezierPath
,将路径设置为 CAShapeLayer
的 .path
属性,然后像这样动画显示 CAShapeLayer
的描边: // Get a path
let path = createBezierPath()
// Shape layer properties
let color = randomCGColor() // Color of path and shadow
let lineWidth = CGFloat(arc4random_uniform(50) + 11) // Width of line and shadow radius
shapeLayer.path = path.CGPath
shapeLayer.lineJoin = kCALineJoinRound
shapeLayer.lineCap = kCALineCapRound
shapeLayer.strokeColor = color
shapeLayer.lineWidth = lineWidth
shapeLayer.fillColor = UIColor.clearColor().CGColor
// Shape layer shadow properties
shapeLayer.shadowPath = path.CGPath
shapeLayer.shadowColor = color
shapeLayer.shadowOffset = CGSizeZero
shapeLayer.shadowRadius = lineWidth
shapeLayer.shadowOpacity = 1.0
// Add shape layer
self.layer.addSublayer(shapeLayer)
// Stroke path animation
let pathAnimation: CABasicAnimation = CABasicAnimation(keyPath: "strokeEnd")
pathAnimation.fromValue = 0.0
pathAnimation.toValue = 1.0
// Shadow path animation
let shadowPathAnimation: CABasicAnimation = CABasicAnimation(keyPath: "shadowPath")
shadowPathAnimation.fromValue = 0.0
shadowPathAnimation.toValue = path.CGPath
// Animation group
let animationGroup = CAAnimationGroup()
animationGroup.duration = 5.0
animationGroup.animations = [pathAnimation, shadowPathAnimation]
shapeLayer.addAnimation(animationGroup, forKey: "allMyAnimations")
问题是,一旦动画完成,阴影就会应用于整个形状。我希望阴影只应用于
CAShapeLayer
的描边。如何在动画完成后防止阴影应用于整个形状?以下是我所指的问题示例:
createBezierPath()
函数吗? - Edison