iOS13:如何检测状态栏的单击事件? [英] iOS13: how to detect a status bar click event?
本文介绍了iOS13:如何检测状态栏的单击事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的appDelegate中,我覆盖 touchesBegan
来检测何时单击状态栏:
In my appDelegate, I override touchesBegan
to detect when the status bar is clicked:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
CGPoint location = [[[event allTouches] anyObject] locationInView:kWindow];
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
if (CGRectContainsPoint(statusBarFrame, location)) {
///do something
}
}
在iOS 13之前,此方法有效;在iOS 13上则没有.该方法从不执行.我该如何解决?
Before iOS 13, this worked; on iOS 13, it does not. The method is never executed. How can I fix this?
推荐答案
经过研究,我发现状态栏不再是iOS13上应用程序的一部分,而是系统UI(跳板")的一部分.您需要通过 UIStatusBarManager
After some research, I found that the status bar is no longer part of the application on iOS13, it’s part of the system UI ("springboard"). You need to access it via UIStatusBarManager
所以这不再起作用:
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
在iOS 13中,您需要像下面这样获取StatusBar框架:
In iOS 13, you need to get the StatusBar frame like this:
UIStatusBarManager *manager = [UIApplication sharedApplication].keyWindow.windowScene.statusBarManager;
CGRect statusBarFrame = manager.statusBarFrame;
这篇关于iOS13:如何检测状态栏的单击事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文