CameraView
@available(watchOS, unavailable)
@available(visionOS, unavailable)
@MainActor
public struct CameraView : UIViewControllerRepresentable
A SwiftUI view that presents a camera interface for capturing photos and videos.
CameraView wraps UIImagePickerController to provide camera functionality within SwiftUI.
It allows users to capture photos and optionally videos from the device camera.
Example usage:
CameraView(onSaveImage: { image in
// Handle the captured image
}, onSaveVideo: { videoURL in
// Handle the captured video
})
-
Creates and configures the
UIImagePickerControllerused to capture media.Declaration
Swift
@MainActor public func makeUIViewController(context: Context) -> UIImagePickerControllerParameters
contextThe context in which this view controller is created
Return Value
A configured
UIImagePickerControllerinstance -
Updates the view controller with any changes to the SwiftUI view’s state.
This method is required by the
UIViewControllerRepresentableprotocol but is not used in this implementation.Declaration
Swift
@MainActor public func updateUIViewController(_ uiViewController: UIImagePickerController, context: Context)Parameters
uiViewControllerThe view controller to update
contextThe context in which the view controller exists
-
Creates a coordinator to handle the delegate methods of
UIImagePickerController.Declaration
Swift
@MainActor public func makeCoordinator() -> CoordinatorReturn Value
A new coordinator instance
-
A coordinator class that acts as the delegate for the
UIImagePickerController.This class handles the events triggered by the image picker, such as when the user captures a photo or video, or cancels the operation.
See moreDeclaration
Swift
@MainActor public final class Coordinator : NSObject, UIImagePickerControllerDelegate, UINavigationControllerDelegate