我正在尝试实现一个适用于我的应用程序的抖动识别.为此,我将以下代码添加到我的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中,使应用程序委派第一个响应者.因此,它当然不起作用.
让它运作的最佳方法是什么?
解决方法
如果您将应用程序委托更改为UIResponder的子类会发生什么?
编辑
您可以在文档中阅读有关响应者链here的信息.