CAShapeLayer and UIBezierPath
This code will set CAShapeLayer.path to a BezierPath, and add animation on the layer
// let startPoint = CGPoint(x: 100, y:100) let endPoint = CGPoint(x: 400, y: 400) let controlPoint = CGPoint(x: 100, y: 300) let path = UIBezierPath() path.moveToPoint(startPoint) path.addQuadCurveToPoint(endPoint, controlPoint: controlPoint) let layer = CAShapeLayer() layer.path = path.CGPath layer.fillColor = UIColor.clearColor().CGColor layer.strokeColor = UIColor.redColor().CGColor view.layer.addSublayer(layer) animation1() // func animation1() { let animation1 = CABasicAnimation(keyPath: "lineWidth") animation1.fromValue = animation1.toValue = 10 animation1.duration = 5 animation1.repeatCount = Float(INT_MAX) animation1.autoreverses = true let animation2 = CABasicAnimation(keyPath: "strokeStart") animation2.fromValue = 0 animation2.toValue = 1 animation2.duration = 5 animation2.repeatCount = Float(INT_MAX) animation2.autoreverses = true layer.addAnimation(animation1, forKey: "lineWidth") layer.addAnimation(animation2, forKey: "strokeStart") }
For keyPath "strokeStart", from value 0 to value 1 means the strokeStartPoint will move from StartPoint to EndPoint, which makes it like the line shrinking.
0 means the startPoint and 1 means the endPoint











