Tvos Switch Presses

I think I am missing something quite simple, but I can’t get the buttons to click to override correctly.

I am trying to detect a menu button, so I override pressesBegan: and test UIPressTypeMenu . The method captures the press of a menu button and executes my code, but in any case, it immediately follows the application exit.

Here is my overridden method. Does anyone know what I'm doing wrong? Is there anything else that is needed to cancel the automatic exit from the menu? It is almost like there are two respondents. The same goes for the left tap and the right tap. They are recognized, my code is triggered, but then the focus changes anyway, because I did not fully process the event.

I tried the code in the controller of the first kind of application, and the menu is overridden. Then I create an empty view and present this view as view number 2, and I cannot force the methods to override.

 - (void)pressesBegan:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event { for(UIPress *press in presses) { if(press.type == UIPressTypeMenu) { [(UIImageView *) [self.view viewWithTag:100] setUserInteractionEnabled:NO]; } if(press.type == UIPressTypePlayPause) { // play and pause code } } } -(void) pressesEnded:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event { // for(UIPress *press in presses) { if(press.type == UIPressTypeMenu) { // do ButtonA job NSLog(@"test"); } if(press.type == UIPressTypePlayPause) { // do ButtonX job } else { } } } -(void) pressesChanged:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event { // Works fine! for(UIPress *press in presses) { if(press.type == UIPressTypeMenu) { // do ButtonA job } if(press.type == UIPressTypePlayPause) { // do ButtonX job } } } -(void) pressesCancelled:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event { // Works fine! for(UIPress *press in presses) { if(press.type == UIPressTypeMenu) { // do ButtonA job NSLog(@"cancelled"); } if(press.type == UIPressTypePlayPause) { // do ButtonX job } } } 
+5
source share
2 answers

The application exits because you allow the message pressesEnded:withEvent: to return to the top of the responder chain. You should also override this method and not call super if you do not want the application to exit (be careful though: if the user cannot use Menu to exit, they will be extremely upset by you)

The left and right arrows trigger focus changes because they are processed by gesture recognizers and not with the pressesBegan / pressesEnded , so it does not matter if their presentation is redefined.

The event handling guide for iOS provides more details on how gesture recognizers and UIResponder methods interact with each other.

+2
source

don't forget about it on your gameScene:

 override func didMoveToView(view: SKView) { super.didMoveToView(view) } 
0
source

Source: https://habr.com/ru/post/1233437/


All Articles