3

我在 tvOS 上的 Apple 默认 AVPlayerViewController 中发现了一种行为。如果您调用时间线,您可以在其中快退或快进视频,然后如果您将手指放在触摸板的右侧,请不要使用 SiriRemote,“10”标签会出现在当前播放时间旁边

截屏

如果您在没有按下遥控器的情况下移开手指,“10”标签就会消失。

触摸遥控器左侧也一样,只是“10”标签出现在当前播放时间的左侧。

问题是,我怎样才能收到这个事件的回调?用户将手指放在遥控器一侧的事件。

UPD

带有 allowedPressTypes=UIPressTypeRightArrow 的 UITapGestureRecognizer 将在用户从触摸表面释放手指后生成事件。我对一旦用户触摸表面边缘(并且可能让手指静止)就会生成的事件感兴趣

4

1 回答 1

8

经过几天的搜索,我得出结论 UIKit 没有报告此类事件。但是可以使用GameController框架来拦截类似的事件。Siri 遥控器表示为GCMicroGamepad。它具有 BOOL reportsAbsoluteDpadValues应设置为的属性YES。每次用户触摸表面GCMicroGamepad时都会更新它的dpad属性值。dpad属性用float x,y范围不同的值表示[-1,1]。这些值代表 Carthesian 坐标系,其中(0,0)是触摸表面的中心,(-1,-1)是靠近遥控器“菜单”按钮的左下点,(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
        }
    };
}];

希望它可以帮助某人。

于 2015-12-21T14:58:24.000 回答