我试图呈现一个 ImagePicker
,在用户选择图像后,呈现一个图像编辑 ViewController
,用户可以在其中操作图像,然后将编辑后的图像发送回原始 ViewController
。
Question:
Is there a standard or best practice approach starting with an initial ViewControlle, then present an ImagePicker there after another ViewController to do the imaging editing, and then display it all back in the initial ViewController, all while making the transitions look seamless?
Is the suggestion in Try 3 below a good practice method or is there a better example of how to achieve this?
尝试 1。
我最初的想法是通过下面的代码以编程方式呈现 ImagePicker
,然后在选择图像后进行图像编辑 ViewController
。但这种做法似乎并不正确。在选择图像后,我似乎无法让 ImagePicker
正确转至 ViewController
。 (一堆 “Unexpectedly found nil while unwrapping optional value” 显示编辑 ViewController
错误。)
let imagePicker = MyImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = .PhotoLibrary
imagePicker.allowsEditing = false
imagePicker.modalTransitionStyle = UIModalTransitionStyle.CoverVertical
self.presentViewController(imagePicker, animated: true, completion: nil)
尝试 2。
我的第二次尝试是将图像编辑 ViewController
显示为隐藏/透明,紧接着是加载的 ImagePicker
,但这会导致空白背景闪烁。
尝试 3。
所以我遇到了这个建议,这是我第二次尝试使用窗口背景显示当前 ViewController
的图像的变体,这似乎是可能的。 http://xissburg.com/presenting-multiple-modal-view-controllers-at-once/
尝试 4。
我的另一个想法是创建一个单独的 ViewController
来处理一个 ImagePicker
,然后通过界面构建器中的 segues 连接每个 ViewController
.
最佳答案
你试过这样吗,在你的第一个 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.
})
}
关于ios - 如何使用 UIImagePickerController 呈现 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39146446/