【发布时间】:2018-11-03 02:32:05
【问题描述】:
我有一个由贝塞尔路径组成的CAShapelayer,但路径很复杂,而不仅仅是一个正方形。
我需要从曲线底部向上(在 y 轴上) 将 shapelayer 填充颜色设置为黄色。 (在层已经附加了路径)
这里是路径和层曲线:
如果我使用此代码,它将立即为所有区域设置动画。
let animation = CABasicAnimation(keyPath: "fillColor")
animation.fromValue = UIColor.white.cgColor
animation.toValue = curveFillColor!.cgColor
animation.duration = 4
animation.fillMode = .forwards
animation.isRemovedOnCompletion=false
shapeLayer.add(animation, forKey: "fillColor")
形状层代码为:
let shapeLayer = CAShapeLayer()
shapeLayer.fillColor = UIColor.yellow.cgColor
shapeLayer.strokeColor = UIColor.yellow.cgColor
shapeLayer.lineWidth = 2.0
shapeLayer.lineJoin = CAShapeLayerLineJoin.round
shapeLayer.lineCap = CAShapeLayerLineCap.round
shapeLayer.strokeStart = 0
shapeLayer.path = path.cgPath
self.layer.addSublayer(shapeLayer)
【问题讨论】:
标签: swift uibezierpath cashapelayer