Set application delegate as first responder

I am trying to implement shake recognition that works throughout my application. To do this, I add the following code to my xxxAppDelegate.m:

-(BOOL)canBecomeFirstResponder { return YES; } - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event { if (event.type == UIEventSubtypeMotionShake) { NSLog(@"Shaken, not stirred."); } } 

But since in the .h file the delegate is defined as

 @interface xxxAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> 

I can not use

 [self becomeFirstResponder]; 

in .m so that the application passes the first responder. Therefore, of course, this will not work. What would be the best way to make it work?

+4
source share
1 answer

What happens if you change the application delegate to a subclass of UIResponder ?

Edit

In the documentation, you can read about the responder chain here .

+2
source

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


All Articles