如何在iOS 7中使用动画隐藏状态栏? [英] How to hide status bar with animation in iOS 7?

查看:123
本文介绍了如何在iOS 7中使用动画隐藏状态栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Since iOS 7 rolled out, I can't show or hide status bar with animation just like in iOS 6. For now I use NSTimer to control it when to hide.

这是我的代码:

- (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];

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

But unfortunately the way of status bar hiding seems a little bit rough, not fading away. Is someone out there has a solution to this ?

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

I solved the hiding issue, using @hahaha solution. I just need a view to be the background of the status bar, here is my code.

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

来自动画块内,如下例所示:

from within an animation block as in the following example:

@implementation SomeViewController {
    BOOL _statusBarHidden;
}

- (BOOL)prefersStatusBarHidden {
    return _statusBarHidden;
}

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

@end

这篇关于如何在iOS 7中使用动画隐藏状态栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆