According to Apple's guidelines, pressing the menu button on tvOS should return you to the previous menu, until you're at the top menu at which point it should return you to the OS menus. My question is, how do I prevent the default behavior of the menu button and stop it from returning to the OS menus, but then reactivate it when the user is at the top menu of my app?
Navigation button: This circular or ring-shaped button sits near the top of the controller, and it's primarily for navigating menus. Clicking the top, bottom, left, and right sides of the ring allow you to navigate up, down, left, and right in menus.
The Siri Remote can't change your TV inputs, so if you regularly switch between HDMI ports, you'll need that old clicker.
Change the TV button setting on Apple TV. Go to Remotes and Devices, select TV Button, then select either Home Screen or Apple TV App.
You can register a tapGestureRecognizer
and set allowedPressTypes = UIPressTypeMenu
code like so:
UITapGestureRecognizer *tapGestureRec = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
tapGestureRec.allowedPressTypes = @[@(UIPressTypeMenu)];
[self.view addGestureRecognizer:tapGestureRec];
Then whenever the Siri remotes menu button is pressed your handleTap
method will be called, allowing you to add any custom logic you need. Just be aware that blocking the menu button from suspending your application on the root view controller can be a cause for App Store rejection.
You can get more information about detecting gestures here and about pressTypes here.
Swift version of @C_X's answer, which worked for me.
let tapGesture = UITapGestureRecognizer(target: self, action: "handleTap:")
tapGesture.allowedPressTypes = [NSNumber(integer: UIPressType.Menu.rawValue)]
self.view.addGestureRecognizer(tapGesture)
Swift 3 version:
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(MyClass.handleMenuPress(_:)))
tapGesture.allowedPressTypes = [NSNumber(value: UIPressType.menu.rawValue)]
self.view.addGestureRecognizer(tapGesture)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With