title: Animate drawing of a circle
body: <p>I'm looking for a way to animate the drawing of a circle. I have been able to create the circle, but it draws it all together.</p>
  
  <p>Here is my <code>CircleView</code> class: </p>
  
  <pre><code>import UIKit
  
  class CircleView: UIView {
    override init(frame: CGRect) {
      super.init(frame: frame)
      self.backgroundColor = UIColor.clearColor()
    }
  
    required init(coder aDecoder: NSCoder) {
      fatalError("init(coder:) has not been implemented")
    }
  
  
    override func drawRect(rect: CGRect) {
      // Get the Graphics Context
      var context = UIGraphicsGetCurrentContext();
  
      // Set the circle outerline-width
      CGContextSetLineWidth(context, 5.0);
  
      // Set the circle outerline-colour
      UIColor.redColor().set()
  
      // Create Circle
      CGContextAddArc(context, (frame.size.width)/2, frame.size.height/2, (frame.size.width - 10)/2, 0.0, CGFloat(M_PI * 2.0), 1)
  
      // Draw
      CGContextStrokePath(context);
    }
  }
  </code></pre>
  
  <p>And here is how I add it to the view hierarchy in my view controller:</p>
  
  <pre><code>func addCircleView() {
      let diceRoll = CGFloat(Int(arc4random_uniform(7))*50)
      var circleWidth = CGFloat(200)
      var circleHeight = circleWidth
      // Create a new CircleView
      var circleView = CircleView(frame: CGRectMake(diceRoll, 0, circleWidth, circleHeight))
  
      view.addSubview(circleView)
  }
  </code></pre>
  
  <p>Is there a way to animate the drawing of the circle over 1 second? </p>
  
  <p>Example, part way through the animation it would look something like the blue line in this image:</p>
  
  <p><img src="https://i.stack.imgur.com/FP4Hum.png" alt="partial animation"></p>