Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make iPhone status bar disappear when displaying a modal view?

I want to display a modal view, and want it to cover the iPhone's status bar.

I tried setting the modal view controller's wantsFullScreenLayout property to YES; I also set its parent's property to YES as well. This doesn't work, presumably because the modal view displays below the main window's content, which includes the status bar.

My second approach dropped the whole "wantsFullScreenLayout" technique in favor of hiding the status bar just before the modal view is displayed, then turning it back on after the modal view is dismissed. This works until the very end...the modal view's parent view is laid out incorrectly (its navigation bar is partially hidden behind the status bar.) Calling -[view setNeedsLayout] does nothing.

How should I approach this problem?

Thanks.

like image 751
Greg Maletic Avatar asked Feb 02 '10 22:02

Greg Maletic


1 Answers

Joining the discusion late, but I think I can save others some trouble.

I have a VC several pushes into a NavController (let's call that VC the PARENT). Now I want to display a modal screen (the CHILD) with the nav bar AND status bar hidden. After much experimentation, I know this works...

1) Because I present the CHILD VC by calling presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated in the PARENT, the nav bar is not involved anymore (no need to hide it).

2) The view in the CHILD VC nib is sized to 320x480.

3) The CHILD VC sets self.wantsFullScreenLayout = YES; in viewDidLoad

4) just before presenting the CHILD, hide the status bar with [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:YES];

5) dismiss the CHILD VC using a delegate protocol methods in the PARENT, and call [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:YES]; before dismissModalViewControllerAnimated:YES] to make sure the nav bar is drawn in the correct location

Hope this helps.

like image 121
mputnamtennessee Avatar answered Sep 20 '22 10:09

mputnamtennessee