【发布时间】:2023-03-12 22:42:01
【问题描述】:
我之前用过下面的代码,在iOS12上运行得非常好:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
let statusBarRect = UIApplication.shared.statusBarFrame
guard let touchPoint = event?.allTouches?.first?.location(in: self.window) else { return }
if statusBarRect.contains(touchPoint) {
NotificationCenter.default.post(statusBarTappedNotification)
}
}
但它不再适用于 iOS13。有什么想法吗?
【问题讨论】:
-
好的,看起来这是我迄今为止在 iOS13 中找到的唯一工作方式来添加一个虚拟 UIScrollView... 不是最优雅的解决方案,但它至少可以工作:self.dummyScrollview.frame = self.view.frame self.dummyScrollview.contentSize.height = self.view.frame.height + 1 self.dummyScrollview.contentOffset.y = 1 dummyScrollview.delegate = self self.view.addSubview(dummyScrollview) func scrollViewShouldScrollToTop(_ scrollView : UIScrollView) -> Bool { //DO WHATEVER YOU NEED TO ON ON STATUS BAR TAP HERE return false }
-
这是一个在 iOS 13 中仍然有效的解决方案:stackoverflow.com/a/3753976/9087914