iOS:以编程方式创建UIWindow导致错误的位置 [英] iOS: Programmatically creating UIWindow results in wrong position
问题描述
在iOS 5.1.1中,我发现如果我创建了我的UIWindow(我厌倦了IB),并将其框架设置为[UIScreen mainScreen] .bounds,则窗口会在状态栏下显示 。但是,如果我做同样的事情是iOS 6,它会出现在状态栏下方的正确位置。
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];
但是,如果我插入r.origin.y + = 20,则将窗口移动到状态栏下方在iOS 5.1.1中,这并没有解决问题,而且只会变得更加怪异。
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.
在以编程方式创建UIWindow时,在UI中放置UIWindow的正确方法是什么?
谢谢。
What is the proper way to place a UIWindow in iOS when creating it programmatically? Thanks.
推荐答案
而不是 [[UIScreen mainScreen] bounds]
你想要使用 [[UIScreen mainScreen] applicationFrame]
。这将是状态栏下方的屏幕区域(如果可见)。
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).
这篇关于iOS:以编程方式创建UIWindow导致错误的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!