简体   繁体   English

iOS:UIView在启用UITabGestureRecognizer时失去了点击识别功能

[英]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.

相关问题 iOS UITesting点击uiview或PSTCollectionViewCell - iOS UITesting Tap on uiview or PSTCollectionViewCell 在UIButton下添加UIScrollView后失去点击识别 - Losing tap recognition after adding a UIScrollView under a UIButton iOS 检测点击并触摸 UIView - iOS Detect tap down and touch up of a UIView 使用点击手势(iOS)在点击时更改UIView的背景颜色 - Change background color of UIView on tap using tap gesture (iOS) iOS在启用绘制的情况下舍入UIView角 - iOS rounding UIView corners with draw enabled 如何在Swift3 IOS饼图中添加点击手势识别? - How to add tap gesture recognition in Swift3 IOS Pie chart? iOS-使用缩放转换的UIViewAnimation期间无法点击UIView - iOS - can't tap UIView during a UIViewAnimation with a scale transform iOS:UIVIew触摸代表与单击识别器 - iOS: UIVIew touches delegates vs single tap recognizer iOS Swift - 如何在 UITableViewCell 内的 UIView 中仅禁用轻击手势? - iOS Swift - How to disable only tap gesture in UIView inside the UITableViewCell? 是否有办法在UIScrollview中嵌入UIView,而不会丢失iOS中的子视图约束? - Is there is way to embed UIView's in UIScrollview without losing subviews constraints in iOS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM