mardi 12 juillet 2016

UIView not registering touch events when adding to sharedApplication's keyWindow

I have a UIView subclass called messageView which I call from the appDelegate like below

let mesgView = messageView(frame: CGRect(x: application.statusBarFrame.minX, y: application.statusBarFrame.minY+50.0, width: application.statusBarFrame.width, height: 75))

UIApplication.sharedApplication().keyWindow?.addSubview(mesgView)
mesgView.window?.windowLevel = UIWindowLevelStatusBar+1

I call it like this because I need to show a view when the user is in the app and they receive a push notification.

in messageView,

override init(frame: CGRect) {
    super.init(frame: frame)
    self.userInteractionEnabled = true
    self.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(messageView.didTap)))
}

func didTap() {
    print("tapped")
}

However, when tapping on mesgView it does not register a touch. I have also tried doing this with a transparent UIButton with no luck.

Where is the touch being registered?

Aucun commentaire:

Enregistrer un commentaire