【问题标题】:How to hide status bar with animation in iOS 7?如何在 iOS 7 中隐藏带有动画的状态栏?
【发布时间】:2013-10-11 16:41:18
【问题描述】:

自从 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];

现在一切正常!

【问题讨论】:

  • +1 用于更新您的最终解决方案!感谢您的贡献!

标签: ios ios7 statusbar


【解决方案1】:

你需要打电话

[UIViewController setNeedsStatusBarAppearanceUpdate];

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

@implementation SomeViewController {
    BOOL _statusBarHidden;
}

- (BOOL)prefersStatusBarHidden {
    return _statusBarHidden;
}

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

@end

【讨论】:

  • 您知道这一点真是太棒了,谢谢!似乎 setStatusBarHidden:YES 在 iOS5 中基本上没有任何作用。再次感谢。
猜你喜欢
  • 2013-11-18
  • 1970-01-01
  • 1970-01-01
  • 2014-04-11
  • 2023-04-04
  • 1970-01-01
  • 1970-01-01
  • 2014-01-22
  • 1970-01-01
相关资源
最近更新 更多