Search code examples
tvosapple-tvfocus-engine

Apple TV – How to only change focus when "Menu" button is tapped


I'm working on a simple board game. I have buttons in the left column like "New Game", "Settings" etc.(let's call it "Menu View"). The rest of the screen is the "Board View" with the current state of the game.

Is it possible to handle when user taps the "Menu" button on the Apple TV Remote control just to navigate from the "Board View" to my "Menu View" instead of closing my app? I have both "Menu View" and "Board View" in the same controller, maybe I need to adjust the controller hierarchy?

Thanks for help!


Solution

  • Eventually, I noticed overriding pressesEnded won't cancel the Menu button press for the first time after launching the app. Using UITapGestureRecognizer on the other hand does:

        let menuTapGestureRegocnizer = UITapGestureRecognizer(target: self, action: "menuTapped")
        menuTapGestureRegocnizer.allowedPressTypes = [UIPressType.Menu.rawValue]
        view.addGestureRecognizer(menuTapGestureRegocnizer)