Dismissing of UIImagePickerController dismisses presenting view controller also

后端 未结 4 1325
醉酒成梦
醉酒成梦 2021-02-06 02:04

I am working on a project that uses tabbar system. One of the item of tabbar is JobPostingViewController. I Embed it in UINavigationController. There is a UIButton called add ne

相关标签:
4条回答
  • 2021-02-06 02:32

    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.

    0 讨论(0)
  • 2021-02-06 02:34

    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

    Select ViewController

    2 - Set Presentation as: Current Context

    Set current context

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

    0 讨论(0)
  • 2021-02-06 02:49

    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)
    
    0 讨论(0)
  • 2021-02-06 02:51

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

    picker.modalPresentationStyle = .overCurrentContext
    
    0 讨论(0)
提交回复
热议问题