質問

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