2

我已经返回

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];

    RootViewController *rvc = [[[RootViewController alloc] init] autorelease];
    UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:rvc] autorelease];

    self.window.rootViewController = navController;
    [self.window makeKeyAndVisible];
    return YES;

}

View controller-based status bar appearance  is  YES in plist file

当我推动视图控制器状态栏看起来很棒。如下图所示。

在此处输入图像描述

但是当我展示 modelviewcontroller 时,它看起来如下。

在此处输入图像描述

我在我正在展示的 viewcontroller 的 viewDidLoad 方法中编写了以下代码

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
    // iOS 7
    navBar.frame = CGRectMake(navBar.frame.origin.x, 20, navBar.frame.size.width, 44);
}

我想在展示模型视图时显示黑色状态栏。但它没有显示。我试过了

基于视图控制器的状态栏外观在 plist 文件中也不是,但它不起作用。

我的代码在 7.0 以下的所有 ios 版本中运行良好,但在 ios 7.0 及更高版本中运行良好。

有什么解决方案吗?如果有人没有收到我的问题,请告诉我。

4

1 回答 1

4

在这个问题中找到了很好的解决方案。

1) 在 info.plist 中将 UIViewControllerBasedStatusBarAppearance 设置为 NO (选择不让视图控制器调整状态栏样式,以便我们可以使用 UIApplicationstatusBarStyle 方法设置状态栏样式。)

2) 在 AppDelegate 的应用程序:didFinishLaunchingWithOptions 中,调用

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
    [application setStatusBarStyle:UIStatusBarStyleLightContent];
    self.window.clipsToBounds =YES;
    self.window.frame =  CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);

    self.window.bounds = CGRectMake(0, 20, self.window.frame.size.width, self.window.frame.size.height);
}
return YES;
于 2013-10-12T11:18:16.543 回答