Hello,
I've looked about for an easy way to do this but haven't come across anything yet. I'm new to Swift and just starting to look at animating things. In my application I've got a straight line drawn from point A to point B. That works well enough, but I'd like to animate the line drawing itself now. Any help or pointers in the right direction would be appreciated. Thanks.
The net is awash with examples of this. Although most are in objc, it is very easy to convert, as the underlying APIs will respond to code completion. A quick search found the solution below from this source (stackoverflow.com/questions/5526216/animate-the-drawing-of-lines-in-uiview). Converted at this location (objectivec2swift.net/#/converter). You'll need to add the headers and paste those references into your browser. Please let me know if this answers your question by clicking the link below otherwise feel free to revise your original post for clarification.
var path: UIBezierPath = UIBezierPath.bezierPath()
path.moveToPoint(CGPointMake(50.0, 0.0))
path.addLineToPoint(CGPointMake(120.0, 600.0))
//Create a CAShape Layer
var pathLayer: CAShapeLayer = CAShapeLayer.layer()
pathLayer.frame = self.view.bounds
pathLayer.path = path.CGPath
pathLayer.strokeColor = UIColor.redColor().CGColor()
pathLayer.fillColor = nil
pathLayer.lineWidth = 2.0
pathLayer.lineJoin = kCALineJoinBevel
//Add the layer to your view's layer
self.view.layer.addSublayer(pathLayer)
//This is basic animation, quite a few other methods exist to handle animation see the reference site answers
var pathAnimation: CABasicAnimation = CABasicAnimation.animationWithKeyPath("strokeEnd")
pathAnimation.duration = 2.0
pathAnimation.fromValue = NSNumber.numberWithFloat(0.0)
pathAnimation.toValue = NSNumber.numberWithFloat(1.0)
//Animation will happen right away
pathLayer.addAnimation(pathAnimation, forKey: "strokeEnd")