Simple line drawing animation in Swift
<p>I am new to swift and got frustrated with this issue that I'm having.</p>

<p>What I am trying to do is very simple: draw a straight line in the center of the screen and animate it. Sounds very simple, right? Yeah.. so that's what I have at the moment. </p>



<pre class="lang-html prettyprint-override"><code>import UIKit

class Drawings: UIView {


    override func drawRect(rect: CGRect) {

        let screensize: CGRect = UIScreen.mainScreen().bounds
        let screenWidth = screensize.width
        let screenHeight = screensize.height

        //context
        let context = UIGraphicsGetCurrentContext()
        CGContextSetLineWidth(context, 7.0)
        CGContextSetStrokeColorWithColor(context, UIColor.whiteColor().CGColor)

        //path
        CGContextMoveToPoint(context, screenWidth, screenHeight * 0.5)
        CGContextAddLineToPoint(context, screenWidth * 0.5, screenHeight * 0.5)

        CGContextSetLineCap(context, CGLineCap.Round)

        //draw
        CGContextStrokePath(context)

    }

}
</code></pre>

<p>The reason I'm asking is that I've found that I cannot animate it, since it's in drawRect function. Is that true? Need some explanation from you guys. Thanks!</p>

<p><a href="https://i.stack.imgur.com/Bhqmk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Bhqmk.png" alt="Image"></a></p>