是否可以将 PanGestureRecognizer 用于 tvOS?

Is it possible to use PanGestureRecognizer for tvOS?

我刚开始为 tvOS 构建第一个应用程序,我很好奇它的手势识别能力。

我的目标是了解手指在 Apple TV 遥控器上滑动的方向和位移。

我知道如何检测点击或滑动,甚至滑动的方向,但不知道位移,换句话说,我不知道我的手指移动了多少点up/down/left/right。

如果有人知道怎么做,请与我分享。

非常感谢任何形式的帮助。

是的!查看 this Apple 指南了解更多信息。

Tap gesture recognizers can be used to detect button presses. By default, a tap gesture recognizer is triggered when the Select button is pressed. The allowedPressTypes property is used to specify which buttons trigger the recognizer.

例子

正在检测 Play/Pause 按钮

let tapRecognizer = UITapGestureRecognizer(target: self, action: "tapped:")
tapRecognizer.allowedPressTypes = [NSNumber(integer: UIPressType.PlayPause.rawValue)];
self.view.addGestureRecognizer(tapRecognizer)

检测滑动手势

let swipeRecognizer = UISwipeGestureRecognizer(target: self, action: "swiped:")
swipeRecognizer.direction = .Right
self.view.addGestureRecognizer(swipeRecognizer)

要获取触摸位置,请查看 Apple 文档中的 Getting the Location of Touches 部分。您需要为此使用 locationInView

Returns the current location of the receiver in the coordinate system of the given view.