如何在iOS 7中使用animation隐藏状态栏?
自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];
但不幸的是,状态栏隐藏的方式似乎有点粗糙,没有消失。 有人在这里有一个解决scheme?
更新
我解决了隐藏的问题,使用@hahaha解决scheme。 我只需要一个视图作为状态栏的背景,这里是我的代码。
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];
现在一切正常!
你需要打电话
[UIViewController setNeedsStatusBarAppearanceUpdate];
从以下示例中的animation块中:
@implementation SomeViewController { BOOL _statusBarHidden; } - (BOOL)prefersStatusBarHidden { return _statusBarHidden; } - (void)showStatusBar:(BOOL)show { [UIView animateWithDuration:0.3 animations:^{ _statusBarHidden = !show; [self setNeedsStatusBarAppearanceUpdate]; }]; } @end