Siri Remote.定向箭头

Vla*_*oka 3 uigesturerecognizer tvos siri-remote

我在tvOS上的Apple默认AVPlayerViewController中发现了一种行为.如果您调用时间轴,您可以在其中放回或快进视频,然后如果您将手指放在触摸板的右侧而不是SiriRemote,则当前播放时间旁边会出现"10"标签

截图

如果在不按遥控器的情况下移开手指,"10"标签将消失.

触摸遥控器的左侧相同,只有"10"标签出现在当前播放时间的左侧.

问题是,我怎样才能收到此次活动的回调?用户将手指放在遥控器一侧的事件.

UPD

具有allowedPressTypes = UIPressTypeRightArrow的UITapGestureRecognizer将在用户从触摸表面释放手指后生成事件.我对用户触摸表面边缘时会产生的事件感兴趣(并且可能会让手指休息)

Vla*_*oka 7

经过几天的搜索,我得出结论,UIKit没有报告此类事件.但是可以使用GameController框架来拦截类似的事件.Siri遥控器代表GCMicroGamepad.它具有BOOL reportsAbsoluteDpadValues应设置的属性 YES.每次用户触摸表面时GCMicroGamepad都会更新它的dpad属性值.dpad属性用每个float x,y范围变化的值表示[-1,1].这些值表示Carthesian坐标系,其中(0,0)是触摸表面的中心,(-1,-1)是遥控器上"Menu"按钮附近的左下角,(1,1)是右上角的点.

总而言之,我们可以使用以下代码来捕获事件:

@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
        }
    };
}];
Run Code Online (Sandbox Code Playgroud)

希望它对某人有帮助.