Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xcode tvos app exiting issue when overriding menu button

Tags:

xcode

menu

tvos

I am currently writing a tvOS app. I've been detecting and overriding the menu button with tapRecognizer to switch between storyboards and other functions. My issue is when I am on my home screen and press menu it does not exit the app. Instead it remembers the last function I used when overriding the menu button and performs that function. Any thoughts on how to clear the tapRecognizer? Or a function that will exit the app?

I'm overriding the menu button with

in Storyboard1

tapRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(home)];
tapRecognizer.allowedPressTypes = @[[NSNumber numberWithInteger:UIPressTypeMenu]];
[self.view addGestureRecognizer:tapRecognizer];

in my home subroutine I send the user back to my home page storyboard. But from then on the menu button will not exit the app but send me back to storyboard1. thanks, SW

like image 586
Swick Avatar asked Oct 06 '15 16:10

Swick


1 Answers

Instead of using your own gesture recognizer, override pressesBegan:

override func pressesBegan(presses: Set<UIPress>, withEvent event: UIPressesEvent?) {
  if(presses.first?.type == UIPressType.Menu) {
    // handle event
  } else {
    // perform default action (in your case, exit)
    super.pressesBegan(presses, withEvent: event)
  }
}
like image 146
ehynds Avatar answered Sep 22 '22 12:09

ehynds