iOS状态栏不会保持轻松

时间:2014-03-20 20:21:17

标签: ios uinavigationbar uiappearance uistatusbar

在我的App Delegate中,我有以下代码,但它在导航栏上方完全黑暗,在那里你看不到任何东西。如果我删除导航栏的背景图像,它会将其正确显示为轻量级内容,但我不确定当它存在时会阻止它。 UINavigationBar的背景图片是320x44。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    UIImage *theBackground = [[UIImage imageNamed:@"navbar.png"]resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];;
    if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
        // Load resources for iOS 6.1 or earlier
       // UIColor *purple = UIColorFromRGB(0x95cdde);
        [[UINavigationBar appearance] setBackgroundImage:theBackground forBarMetrics:UIBarMetricsDefault];



    } else {
        // Load resources for iOS 7 or later
       // UIColor *purple = UIColorFromRGB(0x95cdde);

        [[UINavigationBar appearance] setBackgroundImage:theBackground forBarMetrics:UIBarMetricsDefault];

    }
    window.rootViewController = tabBarController;
    [window makeKeyAndVisible];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

    return YES;
}

这是导航栏图像 enter image description here

2 个答案:

答案 0 :(得分:1)

好的,这是我的理解。如果我错了,希望有人纠正我。 在iOS 7中,导航栏背景图像也在状态栏下方延伸。因此导航栏背景图像可能会阻止状态栏。

我在我的应用中遇到了同样的问题。我有一个图像选择器,在推动该控制器时,状态栏内容变暗。以下代码为我解决了这个问题

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent
                                            animated:NO];
}

我还必须将UIViewController设置为UINavigationControllerDelegate

答案 1 :(得分:1)

发现这篇文章http://blog.jaredsinclair.com/post/61507315630/wrestling-with-status-bars-and-navigation-bars-on-ios-7帮助我弄清了我的问题。需要在我的plist中添加它

基于ViewController的状态栏外观并将其设置为NO

相关问题