简体   繁体   中英

UITapGestureRecognizer on navigationItem.titleView not working on iOS 11

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)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM