UITapGestureRecognizer on navigationItem.titleView not working on iOS 11

The following code works fine in iOS 10 and below. I recently installed Xcode 9.0 beta 5 and installed iOS 11 beta 7 on iPad Air for testing. Now the remedyMenuTapped method is not executed.

self.remedyMenuView = Bundle.main.loadNibNamed("RemedyMenu", owner: self, options: nil)![0] as? RemedyMenu
self.remedyMenuView?.isHidden = true
self.navigationItem.titleView = remedyMenuView;
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(RemedyDetailVC.remedyMenuTapped(_:)))
self.remedyMenuView?.addGestureRecognizer(tapGesture)
+4
source share
1 answer

I had the same problem with a custom view with a gesture on it placed in the title view, it looks like this is an error with xcode 9 or something has changed in the title for ios 11, which does everything inside the titleView, size 0, 0, I solved it by overriding the intrinsicContentSize property of my user view, in your case "remedyMenuView", for example,

override var intrinsicContentSize: CGSize {
        return CGSize(width: 150, height: 36)
    }

good luck.

+20

Source: https://habr.com/ru/post/1684882/


All Articles