Is it possible to use PanGestureRecognizer for tvOS?

旧巷老猫 提交于 2019-12-12 02:37:07

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/34646272/is-it-possible-to-use-pangesturerecognizer-for-tvos

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!