Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImagePickerView in Camera mode shows all black on dismissViewController on iPad

I have an application which uses a UIImagePickerView to allow the user to either take a picture with their camera or select one from the camera roll using the UIImagePickerView.

After getting a picture, I present a different dialog on top of the picker using [picker presentViewController:myViewController animated:YES completion:nil].

If I run my app as an iPhone app (on my iPad), when I dismiss myViewController using [myviewController.presentingViewController dismissViewControllerAnimated:YES completion:nil] it goes back to either showing the CameraRoll or the CameraFeed to take another picture.

But on the iPad, if I am selecting a picture, it works, but if I am taking a picture using the camera feed, I just get a black screen.

Any idea why?

like image 426
Liron Avatar asked Mar 15 '13 07:03

Liron


1 Answers

On iPad when you are using sources different than camera feed, you are presenting UIImagePickerController in a popover and you can use it as long as you wish. But when you decide to pick up the source UIImagePickerControllerSourceTypeCamera the picker window is presenting full screen and you have two cases:

  1. If you use your custom controls (showsCameraControls = NO) you can take as much pictures as you want with the same controller.
  2. If you use default controls (showsCameraControls = YES), after taking ONE picture you MUST dissmiss the controller because it is unusable again and I guess this is your case. You are putting the next controller on the stack after taking the photo, after that you are trying to go back to your picker controller but it is unusable any more and you can see the black screen.

Apple docs for imagePickerController:didFinishPickingMediaWithInfo: :

If you set the image picker’s showsCameraControls property to NO and provide your own custom controls, you can take multiple pictures before dismissing the image picker interface. However, if you set that property to YES, your delegate must dismiss the image picker interface after the user takes one picture or cancels the operation.

If you want to take another picture in this case you have to go back to your base controller and create the UIImagePickerController instance one more.

I hope this will help.

Edit: The easiest way IMO to rebuild your view controllers stack is to dismiss the picker after taking a photo without animation and after that show the next controller with animation. It will give the user feeling, that the next controller is displayed just after the picker controller without any "flashing".

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [self dismissViewControllerAnimated:NO completion:^{
        [self presentViewController:<newController> animated:YES completion:nil];
    }];
}
like image 102
Artur Ozierański Avatar answered Sep 18 '22 02:09

Artur Ozierański