pearl7721
pearl7721

Reputation: 320

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.

Upvotes: 3

Views: 1705

Answers (1)

jcesarmobile
jcesarmobile

Reputation: 53301

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

Upvotes: 3

Related Questions