[英]iOS: UIView losing tap recognition with UITabGestureRecognizer enabled
I am using an imported button object, Floaty ( https://github.com/kciter/Floaty ) which is a subclass of the UIView class. 我使用的是一个导入的按钮对象,Floaty( https://github.com/kciter/Floaty ),它是UIView类的子类。 In one of the view controllers where I am using this button (which includes a Text Field), the button fails to be selected when tapped if I include the following line to close the keyboard when tapped away from...
在我正在使用此按钮(包括文本字段)的其中一个视图控制器中,如果我在包含以下行时按下键,则在点击时关闭键盘时,按钮无法被选中...
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.dismissKeyboard (_:)))
self.view.addGestureRecognizer(tapGesture)
The idea for how to close the keyboard came from this SO query: iOS - Dismiss keyboard when touching outside of UITextField 关于如何关闭键盘的想法来自这个SO查询: iOS - 在UITextField之外触摸时关闭键盘
I thought part of the issue could be that the Floaty button needs to be in the front, so I added the following line of code, found from this SO query: Losing tap recognition after adding a UIScrollView under a UIButton 我认为问题的一部分可能是Floaty按钮需要在前面,所以我添加了以下代码行,从这个SO查询中找到: 在UIButton下添加UIScrollView后丢失了点击识别
floaty.bringSubviewToFront(self.view)
I added this line to the end of my ViewDidLoad() function in the view where it is used. 我在使用它的视图中将此行添加到了ViewDidLoad()函数的末尾。
(Important maybe to note is that all of the aforementioned code is in the ViewDidLoad function for my view controller) (重要的是要注意,所有上述代码都在我的视图控制器的ViewDidLoad函数中)
Is there another way to handle closing a keyboard when tapping away from a text field? 是否还有另一种方法可以在从文本字段中轻敲时关闭键盘? Or is there something else that I should do to the Floaty (UIView) object to handle tap / touch events?
或者我还应该对Floaty(UIView)对象做些什么来处理点击/触摸事件?
You can try use Hit Testing. 您可以尝试使用点击测试。 With hit testing, you can assign a view that handles touch.
通过点击测试,您可以分配一个可以处理触摸的视图。 This great article explains how to apply hit testing http://smnh.me/hit-testing-in-ios/
这篇很棒的文章介绍了如何应用点击测试http://smnh.me/hit-testing-in-ios/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.