How to present a ViewController using a UIImagePickerController

I try to imagine ImagePicker, and after the user has selected the image, imagine editing the image ViewControllerwhere the user can manipulate the image and then send the edited image back to the original ViewController.

Question:

Is there a standard or best approach, starting with the original ViewControlle, then imagine the ImagePicker there after another ViewController to edit the images and then display it back in the initial ViewController, is it seamless to look at transitions?

Is the suggestion in Try 3 below the good practice method or is there a better example of how to achieve this?

Try 1.

My initial thought was to present the program code ImagePickerthrough the code below, and then change the image ViewControllerafter selecting the image. But this approach did not seem right. It seems that I could not ImagePickerapproach correctly ViewControllerafter the image was selected. (A ViewControllerlot of errors "Unexpectedly found zero when expanding an optional value" were shown during editing ).

    let imagePicker = MyImagePickerController()
    imagePicker.delegate = self
    imagePicker.sourceType = .PhotoLibrary
    imagePicker.allowsEditing = false
    imagePicker.modalTransitionStyle = UIModalTransitionStyle.CoverVertical
    self.presentViewController(imagePicker, animated: true, completion: nil)

Try 2.

My second attempt was to present image editing ViewControlleras hidden / transparent, which immediately started uploaded ImagePicker, but caused some flashes of an empty background.

Try 3.

, , , , ViewController, . http://xissburg.com/presenting-multiple-modal-view-controllers-at-once/

4.

- ViewController, ImagePicker, ViewController segues .

+4
1

, ViewController viewDidLoad .

let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = .PhotoLibrary
imagePicker.allowsEditing = false
imagePicker.modalTransitionStyle = UIModalTransitionStyle.CoverVertical
self.presentViewController(imagePicker, animated: false, completion: nil)

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
    if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {

    }
    dismissViewControllerAnimated(true, completion: {
        //Present your custom editing controller also create `protocol/delegate` for getting editing image back.
    })
}
+2

Source: https://habr.com/ru/post/1652473/


All Articles