Cherif
Cherif

Reputation: 5383

How to position an AVCaptureVideoPreviewLayer inside a view?

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 ?

Upvotes: 2

Views: 1436

Answers (1)

user2320861
user2320861

Reputation: 1431

use previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill

Upvotes: 3

Related Questions