ios - 如何使用 UIImagePickerController 呈现 ViewController

标签 ios swift optimization uiviewcontroller uiimagepickercontroller

我试图呈现一个 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/

相关文章:

ios - RestKit、核心数据、魔法记录、大量数据和滞后的 UI

ios - 使用 sambag 时间选择器时出现问题

r - 使用 R 计算风险值(value)和条件风险值(value)(预期短缺)

c - 使用单个变量/寄存器存储 2 个值(并通过位掩码和/或字长的特定 CPU 指令读取它们)

kotlin - 为什么标准迭代器比Kotlin中的序列要快?

iphone - 需要有关在 iphone 中使用亚马逊产品广告 API 的帮助

IOS - 解码 PCM 字节数组

ios - 变换旋转后定位 View

ios - UITableViewAutomaticDimension 不适用于包含 tableView 的单元格

swift - 在 Swift 中向上滚动时 UITableview 崩溃