Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITapGestureRecognizer on navigationItem.titleView not working on iOS 11

Tags:

ios

swift

ios11

The below code is working 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 doesn't get 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)
like image 727
Homam Avatar asked Sep 01 '17 09:09

Homam


1 Answers

I had the same issue with a custom view with a gesture on it placed in the title view, it looks like is a bug with xcode 9 or something changed in titleview for ios 11 that is making that whatever is inside the titleView has a size of 0, 0, I solved it by overriding the intrinsicContentSize property of my custom view, in your case "remedyMenuView" like so

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

good luck.

like image 120
James Rochabrun Avatar answered Sep 19 '22 08:09

James Rochabrun