In the delegate of UIImagePickerController
when an image is taken with the camera, another view is pushed onto the navigation stack:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
picker.pushViewController(otherViewController, animated: true)
}
In the otherViewController
the navigation bar is made visible:
override func viewDidLoad() {
super.viewDidLoad()
navigationController?.setNavigationBarHidden(false, animated: false)
}
When the < Back
button in the navigation bar is tapped, the navigation bar becomes invisible again, the camera view appears, but the camera image is frozen and tapping the bottom bar buttons has no effect.
Why is that?
A workaround is not to offer the user to navigate back by replacing the Back
button with a Cancel
button. That dismisses the UIImagePickerController and automatically dismisses all higher views on the navigation stack, including the 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
// ...
}
As a result the user would have to start the process again from the beginning instead of just navigating back.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With