1

Okay, so I am making a game for tvOS, and I've overridden the menu button. Basically, if you are in the game and press the menu button, you'll be taken to the main menu. If you are at the main menu and press the menu button, you'll return to the Apple TV home screen.

Here's the code to do that:

- (void)pressesBegan:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
{
    UIPress* p = [presses anyObject];

    switch (p.type) {
        case UIPressTypeMenu:

            NSLog(@"Test");

            if(self.gamestate == kGameStateMainMenu)
            {
                [super pressesBegan:presses withEvent:event];
            }
            else if(self.gamestate == kGameStateResetting)
            {

            }
            else
            {
                self.gamestate = kGameStateResetting;
                [self quitGame];
            }

            break;

        default:
            break;
    }
}

This works properly, but there's one issue: if you exit to the apple TV home screen and go back into the app (without quitting it), then no matter what, pressing the menu button will take you back to the apple TV home screen.

Even stranger, the method above is called, and it will even run the quitGame method. It does not call the [super pressesBegan:presses withEvent:event], at least not in the above method, but it still takes the user to the home screen.

Is this a bug, or am I missing something?

4

2 に答える 2

4

pressesBegan をオーバーライドできるだけでなく、pressesEnded もオーバーライドする必要があります。それ以外の場合は、起動して親のデフォルトの動作を呼び出して、アプリをバックアウトします。

于 2016-01-06T08:53:50.947 に答える
0

Apple TV のホーム画面を終了してアプリに戻り、メニュー ボタンを押しても Apple TV のホーム画面に戻る場合は、おそらく 'pressesEnded' デリゲートを上書きしてそのスーパーも呼び出しているため、このスーパーを削除しますpressesEnded 内で呼び出します。

于 2016-01-24T18:57:53.697 に答える