UIButton in Navigation Bar Not Recognizing Taps in iOS 11

∥☆過路亽.° 提交于 2019-11-29 07:05:52

I found a solution from another developer.

You have to add width and height constraints to the view that wraps all your stuff inside the bar button item. So in my case, the item labeled View needs the constraints.

Here's what to do:

Step 1

Create an @IBOutlet from View to the view controller that has this nav bar.

@IBOutlet weak var myView: UIView!

Step 2

In the containing view controller, inside viewDidLoad() add the constraints:

myView.widthAnchor.constraint(equalToConstant: 63).isActive = true
myView.heightAnchor.constraint(equalToConstant: 33).isActive = true

After that, everything works like it used to.

Adding to Clifton Labrum, this is the way to go. Apple changed the way navigation bars work in iOS 11. This can also be done in Storyboard but through descendant constraints.

The Custom view inside UIBarButtonItem can NOT be given constraints directly. Instead, provide its subviews with constraints, and the Custom view will get its constraints implicitly:

The custom view will implicitly get its size because of those constraints.

This should fix all the weird behavior caused by iOS 11.

it's crazy but: in my situation i have custom NavBar with NavBarItems (rigth button in my case) and IMPORTANT: programmatically added UITapGestureRecognizer(for dismiss keyboard on tap around a textfield):

let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard))
view.addGestureRecognizer(tap)

on iOS 10.3 - all be ok... on 11 - i have only my "tap" action... so when i dismiss TapGestureRecognizer - actions on NavBar start working...

so, if you have some gestures on you screen - just try remove it...

hope it's help for you

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!