Is there any notification when user clicked the statusBar?I want to do something specifically when user click the statusBar so I need to know the event occur time.
Asked
Active
Viewed 980 times
0
-
see this https://stackoverflow.com/questions/3753097/how-to-detect-touches-in-status-bar – Anbu.Karthik Jun 02 '17 at 09:15
-
Possible duplicate of [How to detect touches in status bar](https://stackoverflow.com/questions/3753097/how-to-detect-touches-in-status-bar) – dengApro Jun 02 '17 at 09:56
1 Answers
0
Yes.By the way this is tapped solution.not clicked solution.because status bar is not button like element.:)
Here is swift 3 version:
in Appdelegate function add this line.
let statusBarTappedNotification = Notification(name: Notification.Name(rawValue: "statusBarTappedNotification"))
then add this function.
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)
}
}
Now it's ready for cooking.:) in your view controller where you are using.
NotificationCenter.default.addObserver(forName: statusBarTappedNotification.name, object: .none, queue: .none) { _ in
print("Viola, i have been tapped!!!!")
}

elk_cloner
- 2,049
- 1
- 12
- 13