在我的 appDelegate 中,我覆盖touchesBegan
检测何时单击状态栏:
- (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 上则不然。该方法永远不会被执行。我怎样才能解决这个问题?
经过一番研究,我发现状态栏在iOS13上不再是应用程序的一部分,而是系统UI的一部分(“跳板”)。您需要通过以下方式访问它UI状态栏管理器 https://developer.apple.com/documentation/uikit/uistatusbarmanager
所以这不再有效:
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
在iOS 13中,您需要像这样获取StatusBar框架:
UIStatusBarManager *manager = [UIApplication sharedApplication].keyWindow.windowScene.statusBarManager;
CGRect statusBarFrame = manager.statusBarFrame;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)