1

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.

noob
  • 11
  • 5

3 Answers3

1

Working fine in my case

previewLayer.frame = view.layer.bounds
previewLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill
Awais Fayyaz
  • 2,275
  • 1
  • 22
  • 45
0

In your view controller, set size on viewWillLayoutSubviews

override func viewWillLayoutSubviews() {
    super.viewWillLayoutSubviews()

    previewLayer.frame = camView.bounds
}
Valérian
  • 1,068
  • 8
  • 10
0

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

This simple line of code worked for me.

S.S.D
  • 1,579
  • 2
  • 12
  • 23