title: AVCaptureVideoOrientation not working properly
body: <p>I know this question is all over stack overflow but every answer I use just does not effect the outcome what so ever. My problem is the video orientation is always in landscape left which I've been told is the default videoOrientation. I want it to be in whatever orientation the user is holding the iPhone in (mostly portrait) and here is the code I am using to do that:</p>
  
  <pre><code>        previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
          self.cameraView.layer.addSublayer(previewLayer!)
  
          // Tell the preview layer the orientation to display
          self.previewLayer?.frame = self.view.bounds
  
          if let connection =  self.previewLayer?.connection  {
              let currentDevice: UIDevice = UIDevice.currentDevice()
              let orientation: UIDeviceOrientation = currentDevice.orientation
  
              let previewLayerConnection : AVCaptureConnection = connection
  
              if (previewLayerConnection.supportsVideoOrientation)
              {
                  switch (orientation)
                  {
                  case .Portrait:
                      previewLayerConnection.videoOrientation = AVCaptureVideoOrientation.Portrait
                      break
                  case .LandscapeRight:
                      previewLayerConnection.videoOrientation = AVCaptureVideoOrientation.LandscapeLeft
                      break
                  case .LandscapeLeft:
                      previewLayerConnection.videoOrientation = AVCaptureVideoOrientation.LandscapeRight
                      break
                  case .PortraitUpsideDown:
                      previewLayerConnection.videoOrientation = AVCaptureVideoOrientation.PortraitUpsideDown
                      break
  
  
                  default:
                      previewLayerConnection.videoOrientation = AVCaptureVideoOrientation.Portrait
                      break
                  }
              }
          }
  
          captureSession.startRunning()
      }
  </code></pre>
  
  <p>For some reason this does not work I still end up getting everything in landscape left. I think the problem lies in the previewLayer, I feel like I was supposed to assign it to something other than:</p>
  
  <pre><code>previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
  </code></pre>
  
  <p>Because otherwise it should work but I don't know what to do please help me out I've been on this for hours and hours!</p>