【问题标题】:Present a view controller on top of UIImagePickerController instead of dismissing the UIImagePickerController在 UIImagePickerController 之上呈现一个视图控制器,而不是关闭 UIImagePickerController
【发布时间】:2019-11-15 10:25:42
【问题描述】:

我正在开发一个应用程序,我必须使用图像选择器控制器从手机库中导入图像。问题是我必须首先关闭选择器控制器,然后在选择器控制器关闭后呈现另一个控制器。有没有一种方法可以让我不必关闭图像选择器控制器,而是提供视图控制器或导航控制器。顺便说一句,如果我不关闭 imagePickerController,它会崩溃。其次,我展示了一个视图控制器,它传递了被选中的图像。 谢谢。

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {

        let shViewController = SHViewController()

        if let editedImage = info[UIImagePickerController.InfoKey.editedImage] as? UIImage {
            shViewController.image = editedImage
        } else if let originalImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
            shViewController.image = originalImage
        }


        shViewController.delegate = self

        dismiss(animated: true, completion: nil)
        present(shViewController, animated: true, completion: nil)
    }

【问题讨论】:

  • 尝试picker.present(shViewController, animated: true, completion: nil)并评论dismiss(animated: true, completion: nil)
  • dismiss的完成处理程序中调用present

标签: ios swift uiimagepickercontroller viewcontroller


【解决方案1】:

你不能从同一个 vc 中呈现 2 个 vc,所以要么

picker.present(shViewController, animated: true, completion: nil)

dismiss(animated:false) {
   self.present(shViewController, animated: true, completion: nil)
}

【讨论】:

  • 谢谢。然后出现的第二个代码块关闭具有相同的问题,它关闭然后等待 2 秒,然后显示没有解决问题的控制器。但是,当您展示 shViewController 时,您展示选择器的第一个代码对我有用。问题出现在我关闭 shViewController 的地方,并且选择器仍然没有被关闭。
  • 试试dismiss(animated: false)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-03-25
  • 1970-01-01
  • 2016-11-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多