经过几天的搜索,我得出结论 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
}
};
}];
希望它可以帮助某人。