ios - 区分 UITableViewCell 上的单击和双击

标签 ios swift uitableview uigesturerecognizer uitapgesturerecognizer

我在 tableViewCell 中添加了一个 UITapGestureRecogniser ,它可以识别用户是否双击了单元格。如果我双击该单元格,则会自动调用函数 didSelectRowAtIndexPath 。我只希望如果用户在单元格上双击而不是同时双击,则调用手势识别器的函数。有人有办法解决这个问题吗?

最佳答案

在viewDidLoad函数中:

let aSelector : Selector = “start:”
let tapGesture = UITapGestureRecognizer(target: self, action: aSelector)
tapGesture.numberOfTapsRequired = 1
view.addGestureRecognizer(tapGesture)

let bSelector : Selector = “stop:”
let doubleTapGesture = UITapGestureRecognizer(target: self, action: bSelector)
doubleTapGesture.numberOfTapsRequired = 2
view.addGestureRecognizer(doubleTapGesture)

tapGesture.requireGestureRecognizerToFail(doubleTapGesture)

单击时将调用 aSelector 操作,双击时将调用 bSelector。

关于ios - 区分 UITableViewCell 上的单击和双击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33757942/

相关文章:

ios - Swift 将对象从一个数组正确添加到另一个数组?

ios - VOIP 推送通知

ios - 将信息页面添加到 mapkit 应用程序

ios - 如何在嵌套的 Realm 列表中创建新对象?父对象应保持不变,但必须将其 "holds"添加到列表中

ios - GoogleMaps cocoapod 中缺少 GMSPlace viewport 成员

iphone - 重现 iPhone SMS 应用程序用户界面的最简单方法?

ios - 'NSInternalInconsistencyException',原因 : 'Requested the number of rows for section (0) which is out of bounds.'

objective-c - 创建缩略图库的最佳方式

java - 为 iOS 应用程序测试自动化设置 appium

ios - 内存警告 UIImagePickerController