导航栏中的UIButton无法识别iOS 11中的水龙头 [英] UIButton in Navigation Bar Not Recognizing Taps in iOS 11
问题描述
我在 UIImage
和 UILabel
顶部的导航栏中有一个 UIButton
.在iOS 10上运行正常,但是在iOS 11中,它无法从我的 @IBAction
插座中识别出任何轻拍.
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.
我尝试将水龙头插座移到条形按钮项上,但是那也不起作用. UIButton
具有以下约束:
I tried moving the tap outlet to the bar button item, but that didn't work either. The UIButton
has the following constraints:
我通过给它提供绿色背景来确认它在那里,所以我知道它是可见的并且可用.
I confirmed that it's there by giving it a green background, so I know it's visible and available.
知道发生了什么事吗?
推荐答案
我找到了另一个开发人员的解决方案.
I found a solution from another developer.
您必须在将所有内容包装在条形按钮项内的视图中添加宽度和高度约束.因此,在我的情况下,标有 View
的项目需要约束.
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.
这是做什么:
第1步
从 View
创建具有该导航栏的视图控制器的 @IBOutlet
.
Create an @IBOutlet
from View
to the view controller that has this nav bar.
@IBOutlet weak var myView: UIView!
第2步
在包含的视图控制器的 viewDidLoad()
内添加约束:
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.
这篇关于导航栏中的UIButton无法识别iOS 11中的水龙头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!