0

I'm writing my first iOS app and have noticed that the top bar appears over my application:

enter image description here

My main window is created like this:

_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

I noticed this similar question, but I do not have a navigation controller. My root controller is a tab controller.

How can I fix this?

Community
  • 1
  • 1
me--
  • 1,978
  • 1
  • 22
  • 42

1 Answers1

0

You should use applicationFrame instead of bounds. bounds will return you size including status bar while applicationFrame will return you frame of content for your app.

_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];

In iOS7 status bar can be translucent. This means that applicationFrame and bounds will return same frame because content can be drawn bellow status bar. To fix this you can offset you window bellow status bar (20px)

_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
_window.clipsToBounds = YES;
_window.frame =  CGRectMake(0, 20, _window.frame.size.width, _window.frame.size.height - 20);
_window.bounds = CGRectMake(0, 20, _window.frame.size.width, _window.frame.size.height);

To make this work on all versions, add system version condition, like this:

_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
    _window.clipsToBounds = YES;
    _window.frame =  CGRectMake(0, 20, _window.frame.size.width, _window.frame.size.height - 20);
    _window.bounds = CGRectMake(0, 20, _window.frame.size.width, _window.frame.size.height);
}

It's still better to avoid modifying window frame, use applicationFrame and offset your content view for 20px from the top on iOS7 with translucent status bar.

XeNoN
  • 694
  • 6
  • 16