如何检测UIStatusBar的隐藏和显示? [英] How can I detect UIStatusBar hide and show?

查看:47
本文介绍了如何检测UIStatusBar的隐藏和显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试检测iPhone的UIStatusBar的隐藏和显示,但失败了.有什么解决方案可以帮助我,例如KVO或其他吗?

I'm trying to detect hidden and show of iPhone's UIStatusBar but failed. Are there any solution can help me, like KVO or something else?

推荐答案

您可以观察共享的UIApplication实例的statusBarHidden属性.

You can observe the statusBarHidden property of the shared UIApplication instance.

简单的例子:

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    // Do something here...
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    [[UIApplication sharedApplication] addObserver:self forKeyPath:@"statusBarHidden" options:NSKeyValueObservingOptionNew context:NULL];
    [[UIApplication sharedApplication] setStatusBarHidden:YES]; // Will notify the observer about the change
}

这篇关于如何检测UIStatusBar的隐藏和显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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