アプリケーション全体で機能するシェイク認識を実装しようとしています。これを行うには、xxxAppDelegate.m に次のコードを追加します。
-(BOOL)canBecomeFirstResponder {
return YES;
}
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (event.type == UIEventSubtypeMotionShake) {
NSLog(@"Shaken, not stirred.");
}
}
しかし、.h ファイルではデリゲートが
@interface xxxAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate>
使えません
[self becomeFirstResponder];
.m で、アプリがファーストレスポンダーを委任するようにします。したがって、うまくいかないのは当然です。それを機能させるための最良の方法は何ですか?