Pregunta

tl;dr: User interface layout is broken when rotating the iPad while taking a photo, if the app displays a status bar.

I've got an app that shows a status bar that should take photos through a UIImagePickerController.

I'm running this on an iPad 3, iOS 6 with Xcode 4.51

The first problem I noticed was that if I didn't hide the statusbar via

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];

before the call to

[self presentViewController:imagePicker animated:YES completion:nil];

Then the UIImagePickerController would not be shown correctly on the screen. The space for the status bar would still be reserved (but no time or battery information etc. shown) with the result that the controls at the lower end of the screen would be partly off-screen.

So, I added the line

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];

before presenting the UIImagePickerController and the first problem was solved.

Now comes the second problem (caused by the solution to the first problem). When I bring up the UIImagePickerController, rotate the iPad and close it (via "cancel" or "use", doesn't matter), the handler (either imagePickerControllerDidCancel or imagePickerController:didFinishPickingMediaWithInfo: gets called, in which I show the status bar again, via

[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];

The problem is now that the status bar is shown in fact, but the rest of the app seems to be unaware that it is on the screen again. (The UIToolbar that I have on my "MainViewController" is partly hidden behind the status bar.) The interesting thing is, if I rotate the iPad to any other orientation all is displayed correctly again after the animation finishes.

Can anybody give me any tips on how to solve this problem? (Currently my best work around would be to leave the status bar hidden after the first time somebody took a photo, but that's kind of sub-optimal). Maybe there is a better solution to the first problem, or maybe a method to solve both issues.

Further information: After rotating the iPad to landscape while UIImagePickerController was active, this is the frame of my MainViewController's view frame: {{0, 0}, {1024, 768}} (i.e. in the case where there is the problem). When I have the iPad in landscape orientation all the time, this is the MainViewController's view frame after the UIImagePickerController is dismissed: {{0, 0}, {1024, 748}} (This is the case where there is no problem.)

Thanks in advance for your attention and effort!

¿Fue útil?

Solución

I just came across the same issue on iPhone when displaying an image picker that takes an image from the camera. The solution I found was to make a call to show the statusbar when the view that popped up the image picker will re-appear. Eg.

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top