简体   繁体   中英

Is it possible to use PanGestureRecognizer for tvOS?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM