1

I have added a custom view in AppDelegate keyWindow of status bar frame. Before iOS 13, touchbegan was getting called, using which was comparing touch location with the status bar coordinates.

I have searched a lot but couldn't find any thing why touchbegain stopped getting called.

I also tried by hiding the status bar in iOS 13 and than adding subview of status bar frame, this way touchbegan is getting called, but view is getting upside when I hide status bar.

If anyone has any solution for this, kindly post your response.

  • 1
    iOS has the option to make the app fullscreen. There is no need of replacing the statusBar with your view. Just make your app fullscreen. – mutAnT Jan 08 '20 at 05:50
  • This is the requirement for my app to add a custom view for a specific scenario. And I have to identify the click event on that custom view which I was doing with touchbegan method by overriding that into AppDelegate. But from iOS 13, touchbegan stopped getting called for status bar location only i.e. CGRect(0,0,ScreenWidth,20) – user7424029 Jan 08 '20 at 11:56

1 Answers1

0

Try 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
    }
}
  • 1
    That is what my question is that touchbegan not getting called while touching on status bar area. – user7424029 Jan 21 '20 at 09:57
  • This page it say that you need userInteractionEnabled https://stackoverflow.com/questions/30443177/touchesbegan-not-called-in-uiview-subclass try with that. – Edwin Rivas Jan 22 '20 at 16:06
  • In last update of xcode delete some frameworks between them UIKit, go to your target>General in Frameworks add UIKit if you don't have it added. import UIKit to AppDelegate.swift – Edwin Rivas Jan 22 '20 at 16:14