Why can't I draw on an image when I subclass UIView?
<p>I am trying to draw on an image from the camera roll using the code from <a href="http://cocoabite.com/post/110000170154/smooth-drawing-in-swift" rel="nofollow">this tutorial</a>. After selecting a photo from the camera roll, <code>imageView</code> is set to the photo. When the user presses the draw button, <code>tempImageView</code> is added over the photo, so the user can draw onto it. However, when I attempt to draw on the image, nothing happens. Why?</p>

<p>Code:</p>



<pre><code>class EditViewController: UIViewController{
    var tempImageView: DrawableView!
    var imageView: UIImageView = UIImageView(image: UIImage(named: "ClearImage"))

    func draw(sender: UIButton!) {
        tempImageView = DrawableView(frame: imageView.bounds)
        tempImageView.backgroundColor = UIColor.clearColor()
        self.view.addSubview(tempImageView)
    }

}

class DrawableView: UIView {

let path=UIBezierPath()
var previousPoint:CGPoint
var lineWidth:CGFloat=10.0

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override init(frame: CGRect) {
    previousPoint=CGPoint.zero
    super.init(frame: frame)
}

required init?(coder aDecoder: NSCoder) {
    previousPoint=CGPoint.zero
    super.init(coder: aDecoder)
    let panGestureRecognizer=UIPanGestureRecognizer(target: self, action: "pan:")
    panGestureRecognizer.maximumNumberOfTouches=1
    self.addGestureRecognizer(panGestureRecognizer)
}

override func drawRect(rect: CGRect) {
    // Drawing code
    UIColor.greenColor().setStroke()
    path.stroke()
    path.lineWidth=lineWidth
}

func pan(panGestureRecognizer:UIPanGestureRecognizer)-&gt;Void
{
    let currentPoint=panGestureRecognizer.locationInView(self)
    let midPoint=self.midPoint(previousPoint, p1: currentPoint)

    if panGestureRecognizer.state == .Began
    {
        path.moveToPoint(currentPoint)
    }
    else if panGestureRecognizer.state == .Changed
    {
        path.addQuadCurveToPoint(midPoint,controlPoint: previousPoint)
    }

    previousPoint=currentPoint
    self.setNeedsDisplay()
}

func midPoint(p0:CGPoint,p1:CGPoint)-&gt;CGPoint
{
    let x=(p0.x+p1.x)/2
    let y=(p0.y+p1.y)/2
    return CGPoint(x: x, y: y)
}

}
</code></pre>