tvos - 获取 Siri Remote 方向(或获取更改通知?)

标签 tvos orientation-changes apple-tv siri-remote

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

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

最佳答案

我也没有看到 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
}

关于tvos - 获取 Siri Remote 方向(或获取更改通知?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34319236/

相关文章:

uitabbarcontroller - 如何停止隐藏在 tvos 更改焦点中的 TabBar

objective-c - tvOS 如何识别 Objective C 的远程手势?

swift - 我们如何使用 TapGesture 在 Tvos 中播放视频

app-store - 是否需要捆绑显示名称

swift - 在 tvOS 上的 SwiftUI 中更改按钮的颜色

android - 方向更改后 Recyclerview 未填充数据

android - 是什么导致 ListView 在方向更改后保持其滚动位置?

android - 访问方向变化的 fragment View

tvos - 将 GCController 与 tvOS 模拟器一起使用

ios - AirPlay 到 Apple TV 全屏