noob
noob

Reputation: 11

How to set previewLayer (camera view) to fill view

i have a view and would like the camera to display in the whole view in the grey area. currently it only display, shown in the black area.

[current situation faced]

enter image description here

i am using xcode, swift 4, for iOS 11.

May I know how to make my camera view fill the grey part?

currently for my preview layer i did:

previewLayer = AVCaptureVideoPreviewLayer(session: captureSession) self.previewLayer.frame = self.camView.layer.bounds previewLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill self.camView.layer.insertSublayer(previewLayer!, at: 0)

I have also set constraint for bottom, left, right to be 0. Thank you.

Upvotes: 1

Views: 465

Answers (3)

Awais Fayyaz
Awais Fayyaz

Reputation: 2415

Working fine in my case

previewLayer.frame = view.layer.bounds
previewLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill

Upvotes: 1

S.S.D
S.S.D

Reputation: 1686

videoPreviewLayer?.frame = self.view.layer.frame

This simple line of code worked for me.

Upvotes: 0

Valérian
Valérian

Reputation: 1118

In your view controller, set size on viewWillLayoutSubviews

override func viewWillLayoutSubviews() {
    super.viewWillLayoutSubviews()

    previewLayer.frame = camView.bounds
}

Upvotes: 0

Related Questions