iOS: Programmatically creating UIWindow results in wrong position

為{幸葍}努か 提交于 2019-12-07 06:10:45

问题


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.


回答1:


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).




回答2:


I think you probably need to do this:

self.window.windowLevel = UIWindowLevelStatusBar + 1;


来源:https://stackoverflow.com/questions/12716725/ios-programmatically-creating-uiwindow-results-in-wrong-position

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!