如何使用UIImagePickerController呈现ViewController

use*_*509 5 optimization uiviewcontroller uiimagepickercontroller ios swift

我试图呈现一个ImagePicker,在用户选择了图像之后,呈现图像编辑ViewController,用户可以在其中操作图像,然后将编辑后的图像发送回原始图像ViewController.

题:

是否有标准或最佳实践方法从初始ViewControlle开始,然后在另一个ViewController之后呈现ImagePicker进行成像编辑,然后将其全部显示在初始ViewController中,同时使转换看起来无缝?

下面的尝试3中的建议是一个好的练习方法还是有更好的例子来说明如何实现这一点?

试试1.

我最初的想法是ImagePicker通过下面的代码以编程方式呈现,然后在选择图像ViewController后进行图像编辑.但这种方法似乎并不正确.在拍摄ImagePickerViewController图像之后,我似乎无法正确地将其划分为.(编辑时出现了一堆"意外发现nil,同时展开可选值"错误ViewController.)

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

试试2.

我的第二次尝试是将图像编辑显示ViewController为隐藏/透明,然后立即ImagePicker加载,但这会导致一些空白背景闪烁.

试试3.

所以我遇到了这个建议,这是我第二次尝试使用窗口背景显示当前ViewController可能的当前图像的变体.http://xissburg.com/presenting-multiple-modal-view-controllers-at-once/

试试4.

我的另一个想法是创建一个单独ViewController处理a ImagePicker,然后ViewController通过接口构建器中的segue 连接每个.

Nir*_*v D 2

您是否尝试过这样的操作,在第一次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)
Run Code Online (Sandbox Code Playgroud)

从今起

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.
    })
}
Run Code Online (Sandbox Code Playgroud)