The tap gesture isn't detected on the status bar area?

倖福魔咒の 提交于 2020-07-19 06:18:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!