将应用程序委托设置为第一响应者
我正在尝试实现在我的应用程序中有效的震动识别。为此,我将以下代码添加到我的 xxxAppDelegate.m 中:
-(BOOL)canBecomeFirstResponder {
return YES;
}
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (event.type == UIEventSubtypeMotionShake) {
NSLog(@"Shaken, not stirred.");
}
}
但因为在 .h 文件中,委托被定义为 a,所以
@interface xxxAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate>
我无法
[self becomeFirstResponder];
在 .m 中使用 使应用程序委托成为第一响应者。因此,它当然不起作用。 让它发挥作用的最佳方法是什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果将应用程序委托更改为
UIResponder
的子类,会发生什么?编辑
您可以在此处阅读有关响应者链的信息< /a> 在文档中。
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.