-7.6 C
New York
Monday, January 20, 2025

ios – Is there any approach to develop a customized preview after taking a photograph?


is it doable to develop a customized view for Retake/UsePhoto view?

Right here is the display screen of wanted part:
https://i.sstatic.internet/jtGZ7fhF.png

This preview seems instantly after the photograph is taken. I can both reject the photograph or use the photograph I took.
I would like to alter the design of this one: change the buttons with different buttons, add a textual content field. How can I do that utilizing normal code?

Right here is my code:

struct ImagePicker: UIViewControllerRepresentable {

    @Setting(.presentationMode) personal var presentationMode

    @Binding var state: PhotoViewModel.ImageState
    @Binding var selectedImage: UIImage?

    let sourceType: UIImagePickerController.SourceType

    init(selectedImage: Binding, sourceType: UIImagePickerController.SourceType) {
        self._state = .fixed(.none)
        self._selectedImage = selectedImage
        self.sourceType = sourceType
    }

    init(state: Binding, sourceType: UIImagePickerController.SourceType) {
        self._selectedImage = .fixed(nil)
        self._state = state
        self.sourceType = sourceType
    }

    func makeUIViewController(context: Context) -> UIImagePickerController {
        let picker = UIImagePickerController()
        picker.sourceType = sourceType

        if sourceType == .digital camera {
            picker.cameraDevice = .rear
        }

        picker.delegate = context.coordinator
        picker.allowsEditing = false

        return picker
    }

    func updateUIViewController(_ uiViewController: UIImagePickerController, context: Context) {}

    func makeCoordinator() -> Coordinator {
        Coordinator(self)
    }

    class Coordinator: NSObject, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
        let father or mother: ImagePicker

        init(_ father or mother: ImagePicker) {
            self.father or mother = father or mother
        }

        func imagePickerController(
            _ picker: UIImagePickerController,
            didFinishPickingMediaWithInfo data: [UIImagePickerController.InfoKey: Any]
        ) {
            if let uiImage = data[UIImagePickerController.InfoKey.originalImage] as? UIImage {
                father or mother.state = .picked(uiImage)
                father or mother.selectedImage = uiImage
                father or mother.presentationMode.wrappedValue.dismiss()
            }
        }
    }
}

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles