iOS 7 - 状态栏与视图重叠

ary*_*axt 109 statusbar ios ios7

我有一个ViewController在里面UINavigationcontroller,但导航栏是隐藏的.当我在iOS 7上运行应用程序时,状态栏显示在我的视图之上.有办法避免这种情况吗?

我不想编写任何特定于操作系统的代码.

在此输入图像描述

我试着设置View controller-based status bar appearanceNO,但它并没有解决这个问题.

ary*_*axt 95

Xcode 5 iOS 6/7 Deltas专门用于解决此问题.在故事板中,我将我的视图向下移动了20个像素,在iOS 7上向右看,为了使其与iOS 6兼容,我更改Delta y为-20.

在此输入图像描述

由于我的故事板没有使用自动布局,为了在iOS 6上正确调整视图的高度,我必须设置Delta heightDelta Y.

  • 你的答案是正确的,但不适用于4"显示器.如果你能使它适用于4"显示器,请更新你的答案.提前致谢. (8认同)
  • 为我工作.请注意,为了查看此增量,您必须在故障板的"标识和类型"下取消选择"使用Autolayout". (5认同)
  • 当状态栏高度发生变化时会发生什么?F.ex.:当用户激活热点等时......然后身高是40px ...... (3认同)
  • @AnkitMehta我没有必要为4"iphone做任何具体的事情 (2认同)
  • 我发现除了为ΔY设置-20之外,我还必须将+20设置为ΔHeight (2认同)

Nat*_*n H 69

如果您根本不想要任何状态栏,则需要使用以下数据更新plist:要在plist中执行此操作,请添加以下两个设置:

<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
Run Code Online (Sandbox Code Playgroud)

在iOS 7中,您需要设计一个覆盖透明状态栏的应用程序.例如,请参阅新的iOS 7天气应用程序.

  • 它可能适用于某些情况,但您需要非常小心地隐藏状态栏.仅适用于有理由全屏的视图,如媒体播放器或图像查看器. (5认同)
  • 这实际上是唯一的好答案,因为它将问题的核心修复方式完成.所以:需要upvotes! (3认同)

Vin*_*ent 43

这是UIViewControlleriOS 7上的默认行为.视图将全屏显示,这意味着状态栏将覆盖视图的顶部.

如果你有一个UIViewController内部的UINavigationController和的导航栏是可见的,你可以有下面的代码在你的viewDidLoad或有背景图片的导航栏做的伎俩.

self.edgesForExtendedLayout = UIRectEdgeNone;
Run Code Online (Sandbox Code Playgroud)

如果您隐藏了navigationBar,则必须通过移动20个点来调整所有UIView元素.我没有看到任何其他解决方案.使用自动布局会有所帮助.

以下是用于检测iOS版本的示例代码,如果您想要向后兼容.

NSUInteger DeviceSystemMajorVersion() {
    static NSUInteger _deviceSystemMajorVersion = -1;
    static dispatch_once_t onceToken;

    dispatch_once(&onceToken, ^{
        NSString *systemVersion = [UIDevice currentDevice].systemVersion;
        _deviceSystemMajorVersion = [[systemVersion componentsSeparatedByString:@"."][0] intValue];
    });

   return _deviceSystemMajorVersion;
}
Run Code Online (Sandbox Code Playgroud)

  • 而不是获取,解析和比较系统版本,建议使用`if([self respondsToSelector:@selector(edgesForExtendedLayout)])` (17认同)

com*_*tos 15

只有我自己做的工作解决方案.

这是我的UIViewController子类https://github.com/comonitos/ios7_overlaping

来自UIViewController的1个子类

2从该类中对window.rootViewController进行子类化.

3瞧!

- (void) viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
        CGRect screen = [[UIScreen mainScreen] bounds];
        if (self.navigationController) {
            CGRect frame = self.navigationController.view.frame;
            frame.origin.y = 20;
            frame.size.height = screen.size.height - 20;
            self.navigationController.view.frame = frame;
        } else {
            if ([self respondsToSelector: @selector(containerView)]) {
                UIView *containerView = (UIView *)[self performSelector: @selector(containerView)];

                CGRect frame = containerView.frame;
                frame.origin.y = 20;
                frame.size.height = screen.size.height - 20;
                containerView.frame = frame;
            } else {
                CGRect frame = self.view.frame;
                frame.origin.y = 20;
                frame.size.height = screen.size.height - 20;
                self.view.frame = frame;
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

4添加此项以使状态栏变为白色就在[self.window makeKeyAndVisible]之后; !

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}
Run Code Online (Sandbox Code Playgroud)


Dar*_*hah 13

-(UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

-(void)viewWillLayoutSubviews{

 if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) 
  {
    self.view.clipsToBounds = YES;
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    CGFloat screenHeight = 0.0;
    if(UIDeviceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation]))
        screenHeight = screenRect.size.height;
    else
        screenHeight = screenRect.size.width;
    CGRect screenFrame = CGRectMake(0, 20, self.view.frame.size.width,screenHeight-20);
    CGRect viewFrame1 = [self.view convertRect:self.view.frame toView:nil];
    if (!CGRectEqualToRect(screenFrame, viewFrame1))
    {
        self.view.frame = screenFrame;
        self.view.bounds = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

在plist中添加键---查看基于控制器的状态栏外观:NO