Set App delegate as first responder
-
27-02-2021 - |
Question
I'm trying to implement a shake recognition that works throughout my application. To do this I'm adding 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 because in the .h file the delegate is defined as a
@interface xxxAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate>
I cannot use the
[self becomeFirstResponder];
in the .m to make the app delegate the first responder. Therefore of course it doesn't work. What would be the best way to get it working?
Solution
What happens if you change the app delegate to a subclass of UIResponder
?
Edit
You can read about the responder chain here in the documentation.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow