5

In iOS 5.1.1, I have found that if I create my UIWindow (I'm tired of IB), and set its frame to [UIScreen mainScreen].bounds, the window shows up under the status bar. However if I do the same thing is iOS 6, it appears in the right spot just below the status bar.

CGRect r = [[UIScreen mainScreen] bounds];
self.window = [[UIWindow alloc] initWithFrame: r];
self.detailViewController = [[DetailViewController alloc] init];
self.window.rootViewController = self.detailViewController;
[self.window addSubview: detailViewController.view];
[self.window makeKeyAndVisible];

If however I insert r.origin.y += 20, to move the window below the status bar in iOS 5.1.1, this does not solve the problem and things only get weirder.

What is the proper way to place a UIWindow in iOS when creating it programmatically? Thanks.

RRR
  • 51
  • 1
  • 2
  • I am sure you will have much less problems if you go back to IB. I recently tried to fix layout issues with code and it took hours. I got it working but later tried doing the same with just IB, and a few clicks later it was working even better than my manual coding. I have learned it's best to use the tools are they are intended. Otherwise you hit edge cases which are hard to resolve. – Brennan Oct 08 '12 at 15:22

2 Answers2

2

Instead of [[UIScreen mainScreen] bounds] you'll want to use [[UIScreen mainScreen] applicationFrame]. This will be the area of the screen below the status bar (if visible).

mylogon
  • 2,772
  • 2
  • 28
  • 42
escrafford
  • 2,373
  • 16
  • 19
0

I think you probably need to do this:

self.window.windowLevel = UIWindowLevelStatusBar + 1;
Ian Hoar
  • 932
  • 13
  • 18