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

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


is it potential 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 picture is taken. I can both reject the picture or use the picture I took.
I would like to vary the design of this one: substitute 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<UIImage?>, sourceType: UIImagePickerController.SourceType) {
        self._state = .fixed(.none)
        self._selectedImage = selectedImage
        self.sourceType = sourceType
    }

    init(state: Binding<PhotoViewModel.ImageState>, 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 == .digicam {
            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 guardian: ImagePicker

        init(_ guardian: ImagePicker) {
            self.guardian = guardian
        }

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

author avatar
roosho Senior Engineer (Technical Services)
I am Rakib Raihan RooSho, Jack of all IT Trades. You got it right. Good for nothing. I try a lot of things and fail more than that. That's how I learn. Whenever I succeed, I note that in my cookbook. Eventually, that became my blog. 
rooshohttps://www.roosho.com
I am Rakib Raihan RooSho, Jack of all IT Trades. You got it right. Good for nothing. I try a lot of things and fail more than that. That's how I learn. Whenever I succeed, I note that in my cookbook. Eventually, that became my blog. 

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here


Latest Articles

author avatar
roosho Senior Engineer (Technical Services)
I am Rakib Raihan RooSho, Jack of all IT Trades. You got it right. Good for nothing. I try a lot of things and fail more than that. That's how I learn. Whenever I succeed, I note that in my cookbook. Eventually, that became my blog.