2

I would like to display the camera preview in a square UIView. This is what I am doing :

previewLayer!.connection?.videoOrientation = AVCaptureVideoOrientation.Portrait
mySquareView.layer.addSublayer(previewLayer)

The result is the camera preview automatically resizing to fit entirely in the view.

I want it to fit horizontally and to be cropped vertically.

How to do that ?

Cherif
  • 5,223
  • 8
  • 33
  • 54

1 Answers1

3

use previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill

user2320861
  • 1,391
  • 2
  • 11
  • 28