ios wantsFullScreenLayout statusbar visible

2019-03-22 06:19发布

问题:

I'm facing the following problem, I trying to present a modalViewController and make it cover the entire screen, for example:

[controller setWantsFullScreenLayout:yes];
[myNavController presentModalViewController:controller animated:yes];

the result is that the controller does not cover the entire screen and the status bar is visible on top. I don't really understand why this happens.

回答1:

The wantsFullScreenLayout property does not hide the status bar, it makes the view controller get layed out behind it (and also get layed out behind things like navigation bars). An example of this is the built-in Photos app, where a picture appears behind the status and navigation bar:

To make a modal view controller full screen you need to set the modalPresentationStyle property of your view controller to UIModalPresentationFullScreen. With this enabled, you probably don't need or want to set wantsFullScreenLayout.

To hide the status bar you need to use the setStatusBarHidden:withAnimation: method of UIApplication.



回答2:

Try adding this:

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

Also, if you want it hidden at all times and when the application starts, in your plist file, add Status bar initially hidden to YES.