在呈现viewcontroller时,无法在iOS 6,7上隐藏状态栏

时间:2014-04-09 15:35:16

标签: ios uiview uiviewcontroller statusbar

以下是我的自定义VC演示代码:

-(void)presentViewController:(UIViewController*)vc
{
    UIWindow *w = [[[UIApplication sharedApplication] delegate] window];
    UIViewController *parentController = (TabBarViewController *)[w rootViewController];

    [parentController addChildViewController:vc];
    if ([vc respondsToSelector:@selector(beginAppearanceTransition:animated:)]) // iOS 6
    {
        [vc beginAppearanceTransition:YES animated:YES];
    }
    UIView *toView = vc.view;
    [parentController.view addSubview:toView];
    toView.frame = parentController.view.bounds;

    CGAffineTransform tr = CGAffineTransformScale(self.view.transform, 1.0f, 1.0f);
    toView.transform = CGAffineTransformScale(self.view.transform, 0.01f, 0.01f);;
    CGPoint oldCenter = toView.center;

    toView.center = ((RootViewControllerEx*)vc).cellCenter;

    [UIView animateWithDuration:4.5 animations:^{
            toView.transform = tr;
            toView.center = oldCenter;
    } completion:^(BOOL finished) {

        [vc didMoveToParentViewController:parentController];
        if ([vc respondsToSelector:@selector(endAppearanceTransition)]) // iOS 6
        {
            [vc endAppearanceTransition];
        }

    }];
}

它工作正常但是,在提出的VC我隐藏状态栏:

- (BOOL)prefersStatusBarHidden {
    return YES;
}

当我使用内置presentViewController:animated:completion:呈现我的VC时,隐藏了呈现VC中的状态栏。但是我的代码在iOS 7状态栏上根本没有隐藏,在iOS 6上它更奇怪 - 状态栏被隐藏,但我的视图大小从顶部缩短了状态栏的大小。所以我可以看到iOS 6顶部的黑色空白。在使用自定义VC演示时,我该怎么做才能正确隐藏状态栏?

2 个答案:

答案 0 :(得分:0)

你应该在viewDidLoad中尝试这个来区分IOS 6/7状态栏问题

 if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)])
{
    //IOS 7 - Status Bar Hidden
    [self prefersStatusBarHidden];
    [self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
    self.statusBarHidden = YES;
}
else
{
    // iOS 6 - Status Bar shown
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
    self.statusBarHidden = NO;
}

和隐藏状态栏的方法

 - (BOOL)prefersStatusBarHidden{
return YES;}

并为状态栏添加属性

@property BOOL statusBarHidden;

然后确保您的视图与屏幕大小绑定并正确匹配

我认为这解决了你的问题:)

答案 1 :(得分:-2)

试试这个

在视图中加载了

   [UIApplication sharedApplication].statusBarHidden = YES;

并在plist中设置值

enter image description here

在项目摘要

中设置此项

enter image description here

并在您的界面构建器中

enter image description here