Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Camera view of UIImagePickerController frozen when navigating back to it

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?

like image 889
Manuel Avatar asked Jun 30 '17 01:06

Manuel


1 Answers

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.

like image 106
Manuel Avatar answered Sep 19 '22 13:09

Manuel