自从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];
不幸的是,状态栏隐藏的方式似乎有些粗糙,没有淡出效果。是否有人有解决方法?
更新
我解决了隐藏问题,使用了@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];
现在一切都完美运作!