UIButton in Navigation Bar Not Recognizing Taps in iOS 11

前端 未结 3 1369
心在旅途
心在旅途 2020-12-18 01:09

I have a UIButton in a navigation bar that sits over the top of a UIImage and a UILabel. It worked fine in iOS 10, but now in iOS 11 i

3条回答
  •  抹茶落季
    2020-12-18 01:54

    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.

提交回复
热议问题