在Swift中的UIKeyCommand上添加长手势识别器

在两种不同的情况下,我必须检测蓝牙键盘上的外部触摸:

  • 在空格键上检测到触摸
  • 始终在空格键上检测到长按

我使用了UIKeyCommand类,并且在第一种情况下都可以正常工作,但是长按我不知道该怎么做。

反正有这样做吗? 还是有一种方法可以将UILongPressGestureRecognizer添加到UIKeyCommand?

这是实际的代码:

override var canBecomeFirstResponder: Bool {
    return true
}

override var keyCommands: [UIKeyCommand]? {
    return [
        UIKeyCommand(input: UIKeyCommand.inputDownArrow,modifierflags: [],action: #selector((DownArrowPress))),UIKeyCommand(input: UIKeyCommand.inputUpArrow,action: #selector((UpArrowPress))),UIKeyCommand(input: " ",action: #selector((SpaceKeyPress)))]
}

@objc func DownArrowPress(_ sender: UIKeyCommand) {
         //...
}
@objc func UpArrowPress(_ sender: UIKeyCommand) {
         //...
}
@objc func SpaceKeyPress(_ sender: UIKeyCommand) {
        switch("touch or long touch"){
        case "touch":
            //...
        case "long touch":
            //HOW CAN I DETECT THIS ONE?
        default:
            //...
        }
}
xinandjsl0305 回答:在Swift中的UIKeyCommand上添加长手势识别器

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2939767.html

大家都在问