Last active
October 23, 2020 21:42
-
-
Save rorodriguez116/ba6bb626bdc068fffb64c05a0d2d1b9f to your computer and use it in GitHub Desktop.
CamperaPreview SwiftUI view.
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
import AVFoundation | |
struct CameraPreview: UIViewRepresentable { | |
// 1. | |
class VideoPreviewView: UIView { | |
override class var layerClass: AnyClass { | |
AVCaptureVideoPreviewLayer.self | |
} | |
var videoPreviewLayer: AVCaptureVideoPreviewLayer { | |
return layer as! AVCaptureVideoPreviewLayer | |
} | |
} | |
// 2. | |
let session: AVCaptureSession | |
// 3. | |
func makeUIView(context: Context) -> VideoPreviewView { | |
let view = VideoPreviewView() | |
view.backgroundColor = .black | |
view.videoPreviewLayer.cornerRadius = 0 | |
view.videoPreviewLayer.session = session | |
view.videoPreviewLayer.connection?.videoOrientation = .portrait | |
return view | |
} | |
func updateUIView(_ uiView: VideoPreviewView, context: Context) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment