gpt4 book ai didi

swift - 是否可以将 PanGestureRecognizer 用于 tvOS?

转载 作者:行者123 更新时间:2023-11-28 12:57:33 27 4
gpt4 key购买 nike

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

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

我知道如何检测点击或滑动,甚至是滑动的方向,但不知道位移,换句话说,我不知道我的手指向上/向下/向左/向右移动了多少点。

如果有人知道如何做这样的事情,请与我分享。

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

最佳答案

是的!检查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.

示例

检测播放/暂停按钮

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)

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

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

关于swift - 是否可以将 PanGestureRecognizer 用于 tvOS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34646272/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com