OGeek|极客世界-中国程序员成长平台

标题: iphone - 在 ios 7 中呈现 Model View Controller 时出现状态栏问题 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 04:36
标题: iphone - 在 ios 7 中呈现 Model View Controller 时出现状态栏问题

我已经回来了

- (BOOL)applicationUIApplication *)application didFinishLaunchingWithOptionsNSDictionary *)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

当我推送 View Controller 时,状态栏看起来很棒。如下图所示。

enter image description here

但是当我展示 Model View Controller 时,它看起来如下。

enter image description here

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

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

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

基于 View Controller 的状态栏外观在 plist 文件中也是 NO 但它不起作用。

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

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



Best Answer-推荐答案


this question 中找到了很好的解决方案.

1) 在 info.plist 中将 UIViewControllerBasedStatusBarAppearance 设置为 NO(选择不让 View Controller 调整状态栏样式,以便我们可以使用 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;

关于iphone - 在 ios 7 中呈现 Model View Controller 时出现状态栏问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19331466/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4