Stop Menu Button going back to previous view

How do I stop the menu button from going back to the previous view in a UIKit tvOS app? A previous post suggested using GCEventViewController instead of UIViewController with controllerUserInteractionEnabled=false, but this does not work. Also, I noticed that only pressesBegan gets fired, but pressesEnded never fires. Any ideas? I noticed other apps have the menu button pop-up stuff instead of going backward.

Accepted Reply

It works for me using a UITapGestureRecognizer.

Set up the menu button press gesture recognizer:

let menuPressRecognizer = UITapGestureRecognizer()
menuPressRecognizer.addTarget(self, action: "menuButtonAction:")
menuPressRecognizer.allowedPressTypes = [NSNumber(integer: UIPressType.Menu.rawValue)]


Then, when you want to control the response to the menu button press:

self.view.addGestureRecognizer(menuPressRecognizer)


When, you're ready to return to the default behavior of the menu button press:

self.view.removeGestureRecognizer(menuPressRecognizer)


You then just need to respond how you like in your "menuButtonAction:" function.

Replies

It works for me using a UITapGestureRecognizer.

Set up the menu button press gesture recognizer:

let menuPressRecognizer = UITapGestureRecognizer()
menuPressRecognizer.addTarget(self, action: "menuButtonAction:")
menuPressRecognizer.allowedPressTypes = [NSNumber(integer: UIPressType.Menu.rawValue)]


Then, when you want to control the response to the menu button press:

self.view.addGestureRecognizer(menuPressRecognizer)


When, you're ready to return to the default behavior of the menu button press:

self.view.removeGestureRecognizer(menuPressRecognizer)


You then just need to respond how you like in your "menuButtonAction:" function.

precisely,


Thank you, that helped me a lot. Now, only if I can figure out a way to get a UIViewController to unwind via the Exit object 😟


AppsFromTheMountain

Thank you very much!


The only solution that worked for me and i tried a lot.

This works, but not if you set isUserInteractionEnabled on the view to false, which caught me out briefly!