在UIImagePickerController
的委托(delegate)中当用相机拍摄图像时,另一个 View 被推送到导航堆栈上:
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
点击导航栏中的按钮,导航栏再次变得不可见,相机 View 出现,但相机图像被卡住,点击底部栏按钮没有效果。
这是为什么?
最佳答案
解决方法是不通过将 Back
按钮替换为 Cancel
按钮来为用户提供返回导航。这会关闭 UIImagePickerController 并自动关闭导航堆栈上的所有更高 View ,包括 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
// ...
}
因此,用户将不得不从头开始重新开始该过程,而不仅仅是返回。
关于ios - 导航回 UIImagePickerController 的相机 View 时卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44837250/