Dismissing of UIImagePickerController dismisses presenting view controller also

后端 未结 4 1315
醉酒成梦
醉酒成梦 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: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)
    

提交回复
热议问题