iosnotificationsuigesturerecognizerstatusbaruitapgesturerecognizer

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


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.


Solution

  • 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
        }
    }
    

    Note, this no longer works on iOS 13 and newer. For iOS 13 and newer use https://stackoverflow.com/a/59897714/1351469