Dismissing of UIImagePickerController dismisses presenting view controller also

眉间皱痕 提交于 2019-12-03 07:22:34

Adding Picker as subview

try to add the imagepicker as a subview to your CreateJobPostViewController insted of presenting it and then remove it from parent in the delegtes

@IBAction func openCreateJob(sender: AnyObject) {

var picker: UIImagePickerController = UIImagePickerController()
picker.delegate = self
picker.allowsEditing = false
picker.sourceType = .PhotoLibrary
self.addChildViewController(picker)
picker.didMoveToParentViewController(self)
self.view!.addSubview(picker.view!)
}

and then

 func imagePickerControllerDidCancel(picker: UIImagePickerController) {

    picker.view!.removeFromSuperview()
    picker.removeFromParentViewController()
    }

For presenting

showing picker over currentcontext with options like edit cancel choose,

use picker.modalPresentationStyle = .overCurrentContext //before presenting it

 presentViewController(picker, animated: true, completion: nil)

Fixed the issue by setting the image picker's modalPresentationStyle to "OverCurrentContext":

picker.modalPresentationStyle = .overCurrentContext

You could use:

picker.modalPresentationStyle = .overCurrentContext

but depending on your screen layout, it may be better to use:

picker.modalPresentationStyle = .overFullScreen

otherwise your "cancel", "retake" and "use photo" buttons may not be visible.

Edd

I had this same problem, I solved it using the storyboard (Xcode v9.2)

1 - Go to the storyboard, where is your ViewController, select it

2 - Set Presentation as: Current Context

Note: If it does not work Current Context, select Over Current Context

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!