title: Drawing on previewLayer: AVCaptureVideoPreviewLayer
body: <p>I have a small app, a SimpleCamera that shows a live (video) preview, with a button on the screen to take a photo. The photo is then displayed and you can save it or discard it. It all works, and I have used this code to draw a grey border around the screen preview. That too works fine. But that's all I can draw on that preview screen? I can't work out how to add the next bit of code shown below this first code block?</p>
  
  <pre><code>    // Provide a camera preview
      cameraPreviewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
      view.layer.addSublayer(cameraPreviewLayer!)
      cameraPreviewLayer?.videoGravity = AVLayerVideoGravity.resizeAspectFill
      cameraPreviewLayer?.frame = view.layer.frame
      //Add preview layer for drawing
      let previewLayer: AVCaptureVideoPreviewLayer = AVCaptureVideoPreviewLayer(session: self.captureSession)
      previewLayer.frame = self.view.layer.frame
      previewLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill
      self.view.layer.addSublayer(previewLayer)
      //Add Rectangle
      let cgRect = CGRect(x: 0, y: 0, width: self.view.bounds.width, height: self.view.bounds.height)
      let myView = UIImageView()
      myView.frame = cgRect
      myView.backgroundColor = UIColor.clear
      myView.isOpaque = false
      myView.layer.cornerRadius = 10
      myView.layer.borderColor =  UIColor.lightGray.cgColor
      myView.layer.borderWidth = 3
      myView.layer.masksToBounds = true
      previewLayer.addSublayer(myView.layer)
      // Bring the camera button to front
      view.bringSubview(toFront: cameraButton)
      captureSession.startRunning()
  </code></pre>
  
  <p>No matter where I put this code, it simply doesn't show up.</p>
  
  <pre><code>    //Add circles
      let midX = screenWidth / 2
      let midY = screenHeight / 2
      let w = screenWidth
      var circlePath = UIBezierPath(arcCenter: CGPoint(x: midX,y: midY), radius: CGFloat(w * 0.010), startAngle: CGFloat(0), endAngle:CGFloat(Double.pi * 2), clockwise: true)
      let circleRads = [ 0.07, 0.13, 0.17, 0.22, 0.29, 0.36, 0.40, 0.48, 0.60, 0.75 ]
      for pct in circleRads {
          let rad = w * CGFloat(pct)
          circlePath = UIBezierPath(arcCenter: CGPoint(x: midX, y: midY), radius: CGFloat(rad), startAngle: CGFloat(0), endAngle:CGFloat(Double.pi * 2), clockwise: true)
          circlePath.lineWidth = 2.5
          circlePath.stroke()
      }
  
       // draw text time stamp on image
       let now = Date()
       let formatter = DateFormatter()
       formatter.timeZone = TimeZone.current
       formatter.dateFormat = "yyyy-MM-dd HH:mm"
       let dateString = formatter.string(from: now)
       let paragraphStyle = NSMutableParagraphStyle()
       paragraphStyle.alignment = .center
       let attrs = [NSAttributedStringKey.font: UIFont(name: "HelveticaNeue-Thin", size: 26)!, NSAttributedStringKey.paragraphStyle: paragraphStyle]
       let string = dateString
       string.draw(with: CGRect(x: 12, y: 38, width: 448, height: 448), options: .usesLineFragmentOrigin, attributes: attrs, context: nil)
  </code></pre>