首页 文章

UIImagePickerController的相机视图在导航回它时被冻结

提问于
浏览
2

UIImagePickerController 的委托中,当使用相机拍摄图像时,另一个视图被推入导航堆栈:

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    picker.pushViewController(otherViewController, animated: true)
}

otherViewController 中,导航栏可见:

override func viewDidLoad() {
    super.viewDidLoad()
    navigationController?.setNavigationBarHidden(false, animated: false) 
}

当点击导航栏中的 < Back 按钮时,导航栏再次变为不可见,摄像机视图出现,但摄像机图像被冻结,点击底栏按钮无效 .

这是为什么?

2 回答

  • 1

    解决方法是不要通过用 Cancel 按钮替换 Back 按钮来让用户返回导航 . 这解散了UIImagePickerController并自动关闭导航堆栈上的所有更高视图,包括 otherViewController .

    // Replace `Back` button with `Cancel` button in the `otherViewController`
    navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(self.cancelButtonTapped))
    
    @objc func cancelButtonTapped() {
    
       // Dismiss the `UINavigationController`, e.g. by calling a delegate function
       // ...
    }
    

    因此,用户必须从头开始再次启动该过程,而不是仅仅导航回来 .

  • 0

    你在解雇你提出的选择器之前直接推动一个新的视图这就是为什么当你回来你的相机时图像选择器仍然在堆栈上因为它没有被解雇

    dismiss(animated:true, completion: nil)
    

    在此之后,您可以根据需要推送新视图 . didFInish用于获取结果并解除您使用的选择器传递图像选择或单击新控制器(如果需要)但需要解雇选择器

相关问题