This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func prepare(completionHandler: @escaping (Error?) -> Void){ | |
| func createCaptureSession(){ | |
| self.captureSession = AVCaptureSession() | |
| } | |
| func configureCaptureDevices() throws { | |
| let camera = AVCaptureDevice.default(.builtInWideAngleCamera, for: AVMediaType.video, position: .front) | |
| self.frontCamera = camera | |
| try camera?.lockForConfiguration() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| override func viewDidLoad() { | |
| previewView = UIView(frame: CGRect(x:0, y:0, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height)) | |
| previewView.contentMode = UIView.ContentMode.scaleAspectFit | |
| view.addSubview(previewView) | |
| cameraController.prepare {(error) in | |
| if let error = error { | |
| print(error) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension CameraViewController : UIViewControllerRepresentable{ | |
| public typealias UIViewControllerType = CameraViewController | |
| public func makeUIViewController(context: UIViewControllerRepresentableContext<CameraViewController>) -> CameraViewController { | |
| return CameraViewController() | |
| } | |
| public func updateUIViewController(_ uiViewController: CameraViewController, context: UIViewControllerRepresentableContext<CameraViewController>) { | |
| } | |
| } |
OlderNewer