Reputation: 11
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]
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
Reputation: 2415
Working fine in my case
previewLayer.frame = view.layer.bounds
previewLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill
Upvotes: 1
Reputation: 1686
videoPreviewLayer?.frame = self.view.layer.frame
This simple line of code worked for me.
Upvotes: 0
Reputation: 1118
In your view controller, set size on viewWillLayoutSubviews
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
previewLayer.frame = camView.bounds
}
Upvotes: 0