uigesturerecognizertvossiri-remote

Siri Remote. Directional Arrows


I spotted one behaviour in Apple's default AVPlayerViewController on tvOS. If you call up timeline, where you can rewind or fast forward the video, and then if you put and leave your finger on the right side of touchpad don SiriRemote the "10" label appears next to current playback time

Screenshot

If you remove your finger without pressing on the remote, the "10" label disappears.

Same for touching left side of the remote, just the "10" label appears to the left of current playback time.

The question is, how can I receive callback for this event? The event of user putting the finger on the side of remote.

UPD

UITapGestureRecognizer with allowedPressTypes=UIPressTypeRightArrow will generate event after user releases the finger from touch surface. I'm interested in event that will be generated as soon as user touches edge of the surface (and probably leaves the finger resting)


Solution

  • After days of searching I concluded that UIKit does not report such event. But one can use GameController framework to intercept similar event. Siri remote is represented as GCMicroGamepad. It has property BOOL reportsAbsoluteDpadValues that should be set to YES. Than every time user touches the surface GCMicroGamepad will update it's values for dpad property. dpad property is represented with float x,y values that vary in range [-1,1] each. These values represent Carthesian coordinate system where (0,0) is the centre of the touch surface, (-1,-1) is the bottom left point near "Menu" button on the remote, (1,1) is the upper right point.

    Putting all together we can have the following code to catch the event:

    @import GameController;
    
    [[NSNotificationCenter defaultCenter] addObserverForName:GCControllerDidConnectNotification
                                                      object:nil
                                                       queue:[NSOperationQueue mainQueue]
                                                  usingBlock:^(NSNotification * _Nonnull note) {
        self.controller = note.object;
        self.controller.microGamepad.reportsAbsoluteDpadValues = YES;
        self.controller.microGamepad.dpad.valueChangedHandler =
        ^(GCControllerDirectionPad *dpad, float xValue, float yValue) {
    
            if(xValue > 0.9)
            {
                ////user currently has finger near right side of remote
            }
    
            if(xValue < -0.9)
            {
                ////user currently has finger near left side of remote
            }
    
            if(xValue == 0 && yValue == 0)
            {
                ////user released finger from touch surface
            }
        };
    }];
    

    Hope it helps somebody.