印刷机不工作 tvos - swift

presses not working tvos - swift

我正在尝试检测 swift 中的印刷机,但我无法检测到印刷机。这是我的代码:

override func pressesBegan(_ presses: Set<UIPress>, with event: UIPressesEvent?) {
    print("test1")
}

override func pressesChanged(_ presses: Set<UIPress>, with event: UIPressesEvent?) {
    print("test2")
}

override func pressesEnded(_ presses: Set<UIPress>, with event: UIPressesEvent?) {
    print("test3")
}

override func pressesCancelled(_ presses: Set<UIPress>, with event: UIPressesEvent?) {
    print("test4")
}

在实体 apple tv 和模拟器上执行代码后,控制台仍然是空的。为什么未检测到印刷机?任何帮助将不胜感激。

我找到了答案,但我不确定为什么覆盖方法不起作用。

let press:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(pressed))
press.allowedPressTypes = [NSNumber(value: UIPressType.select.rawValue)]
view.addGestureRecognizer(press)