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 } } }
source share