问题
The title explains it all.
Is there any way to detect a tap gesture on the status bar in iOS 11?
I've already googled for this, and tried as suggested, but they all seem to be outdated answers somehow.
I wonder if there's anyone who has already figured out how to solve this.
回答1:
I use this code in the AppDelegate.swift
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) {
// tap on statusbar, do something
}
}
来源:https://stackoverflow.com/questions/51268419/the-tap-gesture-isnt-detected-on-the-status-bar-area