我试图检测iPhone的UIStatusBar的隐藏和显示,但失败了。是否有任何解决方案可以帮助我,如KVO或其他东西?
发布于 2012-10-11 12:23:53
您可以观察共享UIApplication实例的statusBarHidden属性。
简单的例子:
- (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
}发布于 2018-11-15 01:26:49
在iOS 11和更高版本中,您可以子类化视图控制器的UIView并覆盖safeAreaInsetsDidChange
override func safeAreaInsetsDidChange() {
super.safeAreaInsetsDidChange()
// adapt your view
}视图必须与状态栏共享顶端矩形才能正常工作。(但如果不是这样,您可能无论如何都不需要检测更改)。
发布于 2012-10-11 12:23:42
在UIApplication类中,有一个属性statusBarHidden...this告诉状态栏隐藏或返回not...if,表示状态栏是hidden...try this。
https://stackoverflow.com/questions/12832126
复制相似问题