title: Camera Preview Not Fitting To UIView
body: <p>I'm making a camera and I've decided to make it a sort of square like the Instagram camera and the iPhone default camera. I'm encountering a problem where the image doesn't fit the UIView. Below is an example of it happening. The UIView should be covering the red edges to the left and right.</p>
  
  <p><a href="https://i.stack.imgur.com/Gd27I.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Gd27I.png" alt=""></a></p>
  
  <p>Here is the code that starts the session...</p>
  
  <pre><code>func reloadCamera() {
  
      cameraView.backgroundColor = UIColor.clearColor()
  
      captureSession = AVCaptureSession()
  
      captureSession!.sessionPreset = AVCaptureSessionPresetHigh
  
      let backCamera = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
      if (camera == false) {
          let videoDevices = AVCaptureDevice.devicesWithMediaType(AVMediaTypeVideo)
  
          for device in videoDevices {
              let device = device as! AVCaptureDevice
              if device.position == AVCaptureDevicePosition.Front {
                  captureDevice = device
                  break
  
              } else {
                  captureDevice = backCamera
              }
          }
  
      } else {
          captureDevice = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
      }
  
      do {
          let input = try AVCaptureDeviceInput(device: captureDevice)
          if captureSession!.canAddInput(input) {
              captureSession!.addInput(input)
  
              stillImageOutput = AVCaptureStillImageOutput()
              stillImageOutput!.outputSettings = [AVVideoCodecKey: AVVideoCodecJPEG]
              if captureSession!.canAddOutput(stillImageOutput) {
                  captureSession!.addOutput(stillImageOutput)
  
                  previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
                  previewLayer!.videoGravity = AVLayerVideoGravityResizeAspect
                  previewLayer!.connection?.videoOrientation = AVCaptureVideoOrientation.Portrait
                  cameraView.layer.addSublayer(previewLayer!)
                  previewLayer?.frame = cameraView.bounds
  
                  captureSession!.startRunning()
              }
          }
      } catch let error as NSError {
          // Handle any errors
          print(error)
      }
  
  }
  </code></pre>
  
  <p>There are no constraint issues whatsoever and I've tried deleting all elements and only having the code up above run but it didn't work. Tell me if you need any more information. Thanks! (:</p>