title: Drawing on UIImageView in swift
body: <p>I am trying to develop an app where I can draw something on the UIImageView. I have got the following code.</p>
  
  <pre><code>import UIKit
  class Line
  {
      var startPoint:CGPoint
      var endPoint:CGPoint
  
      init (start:CGPoint , end:CGPoint)
      {
          startPoint = start
          endPoint = end
      }
  }
  
  
  class AnnotationView: UIView {
  
      static internal let nibName = "AnnotationView"
      @IBOutlet weak var imageView: UIImageView!
      var lines :[Line] = []
      var lastPoint:CGPoint!
  
  
      override func touchesBegan(_ touches: Set&lt;UITouch&gt;, with event: UIEvent?) {
          lastPoint = touches.first?.location(in: self)
      }
  
      override func touchesMoved(_ touches: Set&lt;UITouch&gt;, with event: UIEvent?) {
          if let touch  = touches.first
          {
              let newPoint = touch.location(in:self)
              lines.append(Line(start: lastPoint, end: newPoint))
              lastPoint = newPoint
              self.setNeedsDisplay()
          }
      }
      override func draw(_ rect: CGRect) {
          if let context = UIGraphicsGetCurrentContext()
          {
              context.beginPath()
              for line in lines
              {
                  context.move(to: line.startPoint)
                  context.addLine(to: line.endPoint)
              }
              context.setLineCap(CGLineCap.round)
              context.setStrokeColor(red: 0, green: 0, blue: 0, alpha: 1)
              context.setLineWidth(5)
              context.strokePath()
          }
      }
  }
  </code></pre>
  
  <p>so now in the above code I have AnnotationView class derived from UIView where I have a UIImageView which I set to full size of the superview from the interface builder. This is a simple drawing app where I want to draw somethings on the UIImageView. Now the problem is when the imageView.image is nil then it does show my drawing and if there is any image set for imageView.image then it doesn't show the drawing. It just show the image that is set in this imageView. I have debugged in both scenarios all the methods get called. There is surely something which I am missing. Can anyone please help me? I want to show my drawing on top of the image which I have set in my UIImageView.
  Regards,
  neena</p>