I am able to animate the stroke of a curve on time series, but this curve is filled with a color, and the color won't animate, i will see the stroke moving and the fill color is already there.
let shapeLayer = CAShapeLayer()
shapeLayer.fillColor = curveFillColor!.cgColor
shapeLayer.strokeColor = curveLineColor!.cgColor
shapeLayer.lineWidth = 3.0
shapeLayer.lineJoin = CAShapeLayerLineJoin.round
shapeLayer.lineCap = CAShapeLayerLineCap.round
shapeLayer.strokeStart = 0
shapeLayer.path = path.cgPath
self.layer.addSublayer(shapeLayer)
let animation = CABasicAnimation(keyPath: "strokeEnd")
animation.fromValue = 0
animation.toValue = 1
animation.duration = 4
shapeLayer.add(animation, forKey: "MyAnimation")
I would like both to animate in the same time for this path, so I get a curve that is slowly being filled with color.
the path
let path = UIBezierPath()
var point1:CGPoint!
var point2:CGPoint!
//var smoothData = self.smooth(alpha: 0.1)
for i in 0..<curvePoints.count-1
{
point1 = curvePoints[i]
point2 = curvePoints[i+1]
point1.y=size!.height-point1.y
point2.y=size!.height-point2.y
if( i == 0 ) {path.move(to: point1)}
path.addLine(to: point2)
}
EDIT: If i animate using this code, it will not animate from left to right with the stroke, just fill it with color :
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")