ios - 导航回 UIImagePickerController 的相机 View 时卡住

标签 ios swift uinavigationcontroller uinavigationbar uiimagepickercontroller

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/

相关文章:

ios - 在 UIimage 上绘制文本时文本大小不一样

ios - 释放单例

iOS Swift UICollectionView registerNib 可重用 View 不起作用

ios - UIBARBUTTON 返回 Action

ios - UINavigationController 标题不显示?

iphone - 在 iPhone 上测试私有(private) API

ios - 如何将核心数据对象从 MapView 发送到 DetailView

swift - 更改所选 UICollectionView 单元格的大小

swift - UnwindSegue 从包含 TableView 的 View Controller 返回到 Root View Controller

objective-c - 有没有办法在不使用 UINavigationController 的情况下更改 iOS 中的 View ?