Tap left-right on Apple TV remote

Is there a way to detect the location of a tap in Apple TV Siri Remote? Actually, I do not need the precise location, but want to know just if the tap is on the left/right/top/bottom side of the remote touchpad. TVOS user interface guidelines suggest that tapping left-right-top-bottom side of remote touchpad does directional navigation, but I can not find how to detect directional tap in tvOS SDK. Also note that directional swipe gesture is not good enough workaround for that.

Accepted Answer

You can use a UITapGestureRecognizer and set the allowed press types to .LeftArrow. Here's the App Programming Guide section on detecting gestures and button presses.


UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
[tapGestureRecognizer setAllowedPressTypes:@[@(UIPressTypeLeftArrow)]];

When you do this, suppose you want one function from which you will handle all taps, like this:


buttonPressedGestureRecognizer.allowedPressTypes = @[[NSNumber numberWithInteger:UIPressTypeSelect],

[NSNumber numberWithInteger:UIPressTypeMenu],

[NSNumber numberWithInteger:UIPressTypePlayPause],

[NSNumber numberWithInteger:UIPressTypeUpArrow],

[NSNumber numberWithInteger:UIPressTypeDownArrow],

[NSNumber numberWithInteger:UIPressTypeRightArrow],

[NSNumber numberWithInteger:UIPressTypeLeftArrow],

];


Then in the target function, how do you determine from the gestureRecognizer argument which button was pressed?


Or is it not possible from a gesture recognizer target, in which case I'd need to use pressesBegan, pressesEnded, etc?

Does the gesture recognizer have to be a UITapGestureRecognizer? I just tried setting allowedPressTypes to observe the Play/Pause button on my UIGestureRecognizer subclass and pressesBegan(_: withEvent:), pressesEnded(), etc are never called.

Is the view with the gesture recognizer the firstResponder? Also if you have a GCEventViewController and controllerUserInteractionEnabled

is set to NO, I think the events might not work for gestures.

Did you ever figure out how to determine which UIPressType it is?


-Brian

Right now I'm just using a different recognizer for each button .

I think this is the way you are supposed to do it.

Tap left-right on Apple TV remote
 
 
Q