Skip to content

Instantly share code, notes, and snippets.

@RosayGaspard
Created January 28, 2020 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RosayGaspard/51c34787d55bdbbd8808b59cfca13694 to your computer and use it in GitHub Desktop.
Save RosayGaspard/51c34787d55bdbbd8808b59cfca13694 to your computer and use it in GitHub Desktop.
func displayPreview(on view: UIView) throws {
guard let captureSession = self.captureSession, captureSession.isRunning else { throw CameraControllerError.captureSessionIsMissing }
self.previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
self.previewLayer?.videoGravity = AVLayerVideoGravity.resizeAspectFill
self.previewLayer?.connection?.videoOrientation = .portrait
view.layer.insertSublayer(self.previewLayer!, at: 0)
self.previewLayer?.frame = view.frame
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment