Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
587 views
in Technique[技术] by (71.8m points)

uinavigationbar - UIButton in Navigation Bar Not Recognizing Taps in iOS 11

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 it doesn't recognize any taps from my @IBAction outlet.

navbar button

I tried moving the tap outlet to the bar button item, but that didn't work either. The UIButton has the following constraints:

enter image description here

I confirmed that it's there by giving it a green background, so I know it's visible and available.

Any idea what's going on?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...