title: How to resize camera aspect ratio after rotation?
body: <p>I have a little Swift program to capture videos. If I start the app with the phone in Landscape mode, then I get the full screen </p>
  
  <p><a href="https://i.stack.imgur.com/bqzog.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bqzog.png" alt="enter image description here"></a></p>
  
  <p>but when I rotate the phone to Portrait, it doesn't fill the whole screen. </p>
  
  <p><a href="https://i.stack.imgur.com/1wgYJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1wgYJ.png" alt="enter image description here"></a></p>
  
  <p>I've tried with resizeAspectFill but it doesn't work. 
  I suspect I have to change the aspect ratio when I rotate the screen to the new aspect ratio but can't seem to find any examples which successfully does it. </p>
  
  <p>Can anyone help please?</p>
  
  <p>The sample code looks something like this:</p>
  
  <pre><code>    cameraPreviewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
      cameraPreviewLayer?.videoGravity = AVLayerVideoGravity.resizeAspectFill
  
      let orientation: UIDeviceOrientation = UIDevice.current.orientation
  
      switch (orientation) {
      case .portrait:
          cameraPreviewLayer?.connection?.videoOrientation = .portrait
      case .landscapeRight:
          cameraPreviewLayer?.connection?.videoOrientation = .landscapeLeft
      case .landscapeLeft:
          cameraPreviewLayer?.connection?.videoOrientation = .landscapeRight
      case .portraitUpsideDown:
          cameraPreviewLayer?.connection?.videoOrientation = .portraitUpsideDown
      default:
          cameraPreviewLayer?.connection?.videoOrientation = .portraitUpsideDown
      }
  
      cameraPreviewLayer?.frame = self.view.frame
  
      self.view.layer.insertSublayer(cameraPreviewLayer!, at: 0)
  </code></pre>
  
  <p>Thanks.</p>