0

I used the code below before, and it worked perfectly fine in iOS12:

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

But it does not work in iOS13 anymore. Any thoughts?

  • Ok, looks like that the only working way in iOS13 I have found so far in to add a dummy UIScrollView... Not the most elegant solution, but it works at least: self.dummyScrollview.frame = self.view.frame self.dummyScrollview.contentSize.height = self.view.frame.height + 1 self.dummyScrollview.contentOffset.y = 1 dummyScrollview.delegate = self self.view.addSubview(dummyScrollview) func scrollViewShouldScrollToTop(_ scrollView: UIScrollView) -> Bool { //DO WHATEVER YOU NEED TO DO ON STATUS BAR TAP HERE return false } – Volodymyr Davydenko Oct 18 '19 at 11:01
  • 1
    Here is a solution which is still works in iOS 13: https://stackoverflow.com/a/3753976/9087914 – JaroslavVegas Nov 07 '19 at 08:29

1 Answers1

3

I've been able to detect the tap with an Objective-C category of UIStatusBarManager. I don't think it's possible as a swift extension or other swift way.

@implementation UIStatusBarManager (CAPHandleTapAction)
-(void)handleTapAction:(id)arg1 {
    // Your code here
}
@end
jcesarmobile
  • 51,328
  • 11
  • 132
  • 176
  • This seems like a great solution but it seems to disable the scroll-to-top behaviour, is there a way to get that back while also using this? – Ben May 19 '20 at 17:27
  • 2
    yeah, but it involves swizzling https://github.com/ionic-team/capacitor/blob/7cb77c87333fb88a2b9d4eefb784d84fe2083c9c/ios/Capacitor/Capacitor/UIStatusBarManager%2BCAPHandleTapAction.m – jcesarmobile May 19 '20 at 18:08