是否可以将 PanGestureRecognizer 用于 tvOS? [英] Is it possible to use PanGestureRecognizer for tvOS?

查看:23
本文介绍了是否可以将 PanGestureRecognizer 用于 tvOS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我的目标是知道手指在苹果电视遥控器上滑动的方向和位移.

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

如果有人知道怎么做,请分享给我.

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

解决方案

是的!查看 Apple 指南以了解更多信息.

<块引用>

点击手势识别器可用于检测按钮按下.经过默认情况下,选择按钮时触发点按手势识别器被按下.allowedPressTypes 属性用于指定哪个按钮触发识别器.

示例

检测播放/暂停按钮

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 = .Rightself.view.addGestureRecognizer(swipeRecognizer)

要获取触摸的位置,请查看 获取 Apple 文档中的触摸位置 部分.为此,您需要使用 locationInView.

<块引用>

返回接收器在坐标系中的当前位置给定的视图.

I just started building first apps for tvOS and I'm curious about its gesture recognition abilities.

My goal is to know the direction and displacement of a finger swipe on the apple tv remote.

I know how I can detect tap or swipe, even the direction of the swipe, but not the displacement, in other words I don't know how many points I moved my finger up/down/left/right.

If anyone knows how to do such thing, please share with me.

Any kind of help is highly appreciated.

解决方案

Yes it is! Check this Apple guide for more information.

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.

Examples

Detecting the Play/Pause button

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

Detecting a swipe gesture

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

To get the location of touches, check the Getting the Location of Touches section in Apples documentation. You need to use locationInView for that.

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

这篇关于是否可以将 PanGestureRecognizer 用于 tvOS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆