Question

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.

Was it helpful?

Solution

You'll be wanting the - (void)setStatusBarHidden:(BOOL)hidden animated:(BOOL)animated on the UIApplication class.

Something like this:

[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];

That should hide the status bar with a nice fade animation.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top