title: How to create a custom camera preview view with UIImagePickerController?
body: <p>Sorry if this question is somewhat broad, but I have been searching for hours without a great solution that fits my specific needs for this problem.</p>
  
  <p>For some background information, the iOS app that I am working on calls for a camera overlay (a png of a mask image) where the user has the ability to place their face in and capture a photo with the mask overlay on top of it. The camera is initially set to the front because the main purpose is to have somewhat of a selfie functionality. After tapping the default capture button, the camera preview image gets mirrored or reversed.</p>
  
  <p>Everything looks great before the photo is captured into camera preview view; however, after it is captured, it gets mirrored or reversed. For example, if I am holding up my left hand while setting up to capture the picture, and I capture that image, the camera preview will look like I am holding up my right hand.</p>
  
  <p>During my research, I have found a couple of solutions that do not exactly fit my needs or fully explain how I could go about solving the problem. My project is exclusively written in Swift, and the management wants to keep it this way at all costs if possible. Below, I will list the solutions that I found:</p>
  
  <ol>
  <li>This project is essentially everything that I need; however, it is written in Objective-C: <a href="https://github.com/lucasecf/LEMirroredImagePicker" rel="nofollow">https://github.com/lucasecf/LEMirroredImagePicker</a></li>
  <li>All of the other solutions that I came upon were either to create a custom camera in its entirety (Capture, Cancel, Use Photo, Retake, Camera Preview, etc.) or to use AVFoundation (Never worked with this and there are not many examples in Swift).</li>
  </ol>
  
  <p>Here is the only code that I have so far pertaining to working with UIImagePickerController:</p>
  
  <pre><code>var picker = UIImagePickerController()
  
  @IBAction func shootPhoto(_ sender: AnyObject) {
      if UIImagePickerController.availableCaptureModes(for: .front) != nil {
          picker = UIImagePickerController() //make a clean controller
          picker.allowsEditing = false
          picker.sourceType = UIImagePickerControllerSourceType.camera
          picker.cameraCaptureMode = .photo
          picker.cameraDevice = .front
          picker.showsCameraControls = true
  
          //customView stuff
          let customViewController = CustomOverlayViewController(
              nibName:"CustomOverlayViewController",
              bundle: nil)
          let customView:CustomOverlayView = customViewController.view as! CustomOverlayView
          customView.frame = self.picker.view.frame
  
          picker.modalPresentationStyle = .fullScreen
          present(picker,animated: true,completion: {
              self.picker.cameraOverlayView = customView
          })
      } else { //no camera found -- alert the user.
          let alertVC = UIAlertController(
              title: "No Camera",
              message: "Sorry, this device has no camera",
              preferredStyle: .alert)
          let okAction = UIAlertAction(
              title: "OK",
              style:.default,
              handler: nil)
          alertVC.addAction(okAction)
          present(alertVC, animated: true, completion: nil)
      }
  }
  </code></pre>
  
  <p>So, if someone can either provide a full-fledged solution or guide me somehow (although, I think I have seen everything on the internet already) that would awesome!</p>