8

我一直在寻找一种方法来检查 Siri Remote 的当前方向或注册 Siri Remote 方向更改,但我还没有找到任何东西。是否有可能做到这一点(不诉诸解释原始重力数据)?

我已经找到了如何使用“microGamepad”上的“allowsRotation”禁用自动方向更改。这很酷!

4

1 回答 1

1

我也没有看到 API,但是正如您提到的,您可以轮询重力数据,我只是想在此处发布该代码,以防有人发现它有用。您可以根据自己的需要对其进行修改,例如检测最后方向并将其与当前方向进行比较,如果您想要回调更改。

    //**************************************************************
    // Update loop portion to UIViewController
    //**************************************************************
    @property (strong) CADisplayLink *updateLoopTimer;
    self.updateLoopTimer = [CADisplayLink displayLinkWithTarget:self selector:@selector(updateRefreshRate:)];
    [self.updateLoopTimer addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    -(void)updateRefreshRate:(CADisplayLink *)displayLink
    {
        CFTimeInterval deltaTime = displayLink.duration * displayLink.frameInterval;
        [self update:(float)deltaTime];
    }

 //******************************************************
// Update loop
//******************************************************
-(void)update:(float)dt
{
#ifdef TV
    //***************************************
    // Detect button presses
    //***************************************
    //self.gameControler = [[GCController controllers] firstObject];
    if( self.gameController != nil )
    {
        GCMicroGamepad* microPad = self.gameController.microGamepad;
        if ( microPad != nil )
        {
            GCMotion *motion = self.gameController.motion;
            GCControllerDirectionPad *dpad = microPad.dpad;

            if( motion != nil )
            {
                GCAcceleration accelVector = motion.gravity;
                if( fabs(accelVector.x) > fabs(accelVector.y) )
                {
                    NSLog(@"Sideways");
                }
                else
                {
                    NSLog(@"Upright");
                }

            }
        }
    }
#endif
}
于 2016-02-01T02:01:38.223 回答