ios - 使用 numberOfTouchesRequired 实现与 TrackPad 的二次点击
问题描述
我想在 iPad 上实现二次点击以显示选项。
let tapTwoRecog = UITapGestureRecognizer(target: self, action: #selector(tapTwoAsLongPress(gesture:)))
tapTwoRecog.numberOfTouchesRequired = 2
tapTwoRecog.numberOfTapsRequired = 1
tapTwoRecog.allowedTouchTypes = [NSNumber(value: UITouch.TouchType.direct.rawValue), NSNumber(value: UITouch.TouchType.indirect.rawValue)]
tableView.addGestureRecognizer(tapTwoRecog)
tableView.isMultipleTouchEnabled = true
但它只能由屏幕上的触摸触发。使用触控板不会触发任何事情。我已经设置UIApplicationSupportsIndirectInputEvents
为YES/NO
.
解决方案
我刚刚从这个网站找到了答案: https ://pspdfkit.com/blog/2020/level-up-your-trackpad-support-using-uiinteraction/
if #available(iOS 13.4, *) {
let tapTwoRecog = UITapGestureRecognizer(target: self, action: #selector(tapTwoAsLongPress(gesture:)))
tapTwoRecog.allowedTouchTypes = [NSNumber(value: UITouch.TouchType.indirectPointer.rawValue)]
tapTwoRecog.buttonMaskRequired = .secondary
tableView.addGestureRecognizer(tapTwoRecog)
}
UIApplicationSupportsIndirectInputEvents
必须YES
是。
推荐阅读
- typescript - 如何在 WebPart 中使用 Azure AD 保护重定向?
- c++ - use QModelIndex to set background of a QTreeWidgetItem
- c++ - 使用 QMap 并获取编译错误消息
- upgrade - MarkLogic 升级和步骤
- android - 如何以编程方式检查 VoLTE 启用
- javascript - 如何从第三方 REST API 获取数据并显示在页面上
- java - 如何在java中将`List`更改为`List of tuple`
- javascript - uuid - 默认导出 (ReactJS - JavaScript)
- c - 如何使大容量存储设备从固件只读到 Windows
- c# - 从基类实例化特定类型的派生类属性