简体   繁体   English

旋转视图时如何在iOS 7中停止状态栏覆盖

[英]How to stop statusbar overlayping in ios 7 when rotating view

i am working compatablity modification for ios 7. My application view is rotating for landscape and portiate mode. 我正在为ios 7进行兼容性修改。我的应用程序视图正在旋转以使用横向和纵向模式。

But currently in ios 7 status bar is overlayping to my view.in all rotation. 但是目前在ios 7状态栏中所有旋转都覆盖到我的view。 I have try with following code but it not work for me. 我尝试使用以下代码,但对我不起作用。

In my appDelegate file appdidfinishlaunching i set 1 notification as follows: 在我的appDelegate文件appdidfinishlaunching中,我设置了1条通知,如下所示:

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
        [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidChangeStatusBarOrientation:)
name:UIApplicationDidChangeStatusBarOrientationNotification
                                                   object:nil];
   }

This will cold method as follows: 这将冷方法如下:

- (void)applicationDidChangeStatusBarOrientation:(NSNotification *)notification
{

    int a = [[notification.userInfo objectForKey: UIApplicationStatusBarOrientationUserInfoKey] intValue];
    int w = [[UIScreen mainScreen] bounds].size.width;
    int h = [[UIScreen mainScreen] bounds].size.height;
    switch(a){
        case 4:
            self.window.frame =  CGRectMake(0,20,w,h);
            break;
        case 3:
            self.window.frame =  CGRectMake(-20,0,w-20,h+20);
            break;
        case 2:
            self.window.frame =  CGRectMake(0,-20,w,h);
            break;
        case 1:
            self.window.frame =  CGRectMake(20,0,w-20,h+20);
    }

}

For the first time when i launch my application status bar was over layping my view. 当我第一次启动应用程序状态栏时,我的视图就已经覆盖了。 Secound time when i rotate my iPad at that time it set status bar black ground on the different possition. 当我旋转iPad的第二时间,它在其他位置将状态栏设置为黑色。 Every time I was getting wrong. 每次我弄错了。

Please help me, Am i doing anything wrong in the above. 请帮助我,我在上面做错了什么吗?

And if possible please provide me sample code for all rotation to stop status bar overlayping. 如果可能,请提供所有旋转的示例代码,以停止状态栏叠加。

您可以使用以下代码停止导航栏的重叠

self.navigationController.navigationBar.translucent = NO;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM