iPhone UIViewController进入状态栏

Man*_*tas 9 iphone layout objective-c uiviewcontroller ios

我有UIView一个UIController观点.我的标准是320x460视图.在applicationDidFinishLaunching我这样做:

[window addSubview:[controller view]];
Run Code Online (Sandbox Code Playgroud)

奇怪的是,它UIView位于状态栏下(就像缺少出口一样).但是,如果我将iPhone旋转到一侧然后再回来,它会显示正常.

这是一种预期的行为(我打赌我可以通过设置偏移来修复它)或者我做错了吗?

Nic*_*anu 18

我通过presentModalViewController显示UIViewController时遇到了这个问题.

您可以通过在视图出现手动调整控制器视图的大小来绕过它:

- (void) viewDidAppear: (BOOL) animated {
    //manually adjust the frame of the main view to prevent it from appearing under the status bar.
    UIApplication *app = [UIApplication sharedApplication];
    if(!app.statusBarHidden) {
        [self.view setFrame:CGRectMake(0.0,app.statusBarFrame.size.height, self.view.bounds.size.width, self.view.bounds.size.height - app.statusBarFrame.size.height)];
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 跟进:我见过的最好的解决方案是打开viewcontroller的nib文件,选择主视图,在"模拟用户界面元素"下,将"状态栏"选项设置为"未指定"之外的任何内容.我无法解释哪些内部值正在被更改,只是这解决了我的应用程序的问题.如果你这样做,你将不需要我之前的答案中的代码. (4认同)

小智 8

我认为您的问题是,当您向窗口添加视图时,您需要了解状态栏的状态并对其进行补偿:

if showing the status bar :
   [controller view].frame = CGRectMake(0, **20**, 320, 460);
else 
   [controller view].frame = CGRectMake(0, 0, 320, **480**);
Run Code Online (Sandbox Code Playgroud)

这就是IB为您显示虚拟状态栏的原因.


小智 5

我今天补充了这个问题.事实证明,我在ViewController的属性检查器中检查了"想要全屏".

关闭"想要全屏"解决了这个问题.