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?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top