I have a scroll-view with a UIImage on top the UIImage has its own view controller class and the scroll view is on the main root-controller. I added the hide status bar method to the root-controller but when开发者_如何学JAVA I run the program the status bar disappears but leaves a white space and the view does not grow over the status bar white space. I tired other methods but I still get the same white space I also tried to enable scroll vertical and it looks like the status bar is on top of all my views, when I scroll up it keeps going up under the status bar.
What could be causing this?
You just hid the status bar, seems like other components did not automatically expand to take over that space. Make sure you have "auto-resize subviews" enabled in all components under main root-controller.
If that doesn't help, you could try relocating and resizing your view in code. Something like:
CGRect frame = self.view.frame;
frame.origin.y -= statusBar.height;
frame.size.height += statusBar.height;
self.view.frame = frame;
I had this same issue I was able to fix it by adding a call to,
// Where self == Your View Controller with the status bar hidden
[self setWantsFullScreenLayout:YES];
Then I placed this in my init method of the View Controller where the status bar is hidden. I then added the following code to the view did load or the view will load method.
if ([[UIApplication sharedApplication] respondsToSelector:@selector(setStatusBarHidden:withAnimation:)]) {
[[UIApplication sharedApplication] setStatusBarHidden:hide withAnimation:NO];
} else { // Deprecated in iOS 3.2+.
id sharedApp = [UIApplication sharedApplication]; // Get around deprecation warnings.
[sharedApp setStatusBarHidden:hide animated:NO];
}
This will allow you to have a view controller with a status bar and one without. The photo app does this for example.
Just a follow-up on JOMs helpful solution with a dynamic statusBar height (no one should rely on a status bar being 20px as indicated a comment):
// fix frame
CGRect frame = window.frame;
if( ! [UIApplication sharedApplication].statusBarHidden ) {
int statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height;
frame.origin.y += statusBarHeight;
frame.size.height -= statusBarHeight;
}
self.view.frame = frame;
btw: in my case I needed to recalculate the frame and adapt it to a visible status bar.
精彩评论