如何在iOS 7中使用动画隐藏状态栏?

xer*_*vim 10 statusbar ios ios7

自iOS 7推出以来,我无法像iOS 6那样显示或隐藏动画状态栏.现在我使用NSTimer控制它何时隐藏.

这是我的代码:

- (void)hideStatusBar{
    _isStatusBarHidden=YES;
    [self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
}
- (void)showStatusBar{
_isStatusBarHidden=NO;
[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
}
    //===================
 _controlVisibilityTimer = [[NSTimer scheduledTimerWithTimeInterval:4 target:self selector:@selector(hideStatusBar:) userInfo:nil repeats:NO] retain];
Run Code Online (Sandbox Code Playgroud)

但不幸的是,状态栏隐藏的方式似乎有点粗糙,没有消失.有人在那里有解决方案吗?

更新

我使用@hahaha解决方案解决了隐藏问题.我只需要一个视图作为状态栏的背景,这是我的代码.

AppDelegate* appDelegate = (AppDelegate*)[[UIApplication sharedApplication]delegate];

self.StatusBarOrange = [[UIView alloc] initWithFrame:CGRectMake(0, 0, appDelegate.window.frame.size.width, 20)];    
[self.StatusBarOrange setBackgroundColor:[UIColor orangeColor]];
[appDelegate.window.rootViewController.view addSubview:self.StatusBarOrange];
Run Code Online (Sandbox Code Playgroud)

现在一切都很完美!

Wer*_*her 34

你需要打电话

[UIViewController setNeedsStatusBarAppearanceUpdate];
Run Code Online (Sandbox Code Playgroud)

从动画块中,如下例所示:

@implementation SomeViewController {
    BOOL _statusBarHidden;
}

- (BOOL)prefersStatusBarHidden {
    return _statusBarHidden;
}

- (void)showStatusBar:(BOOL)show {
 [UIView animateWithDuration:0.3 animations:^{
        _statusBarHidden = !show;
        [self setNeedsStatusBarAppearanceUpdate];
    }];
}

@end
Run Code Online (Sandbox Code Playgroud)