objective-c – 将App delegate设置为第一响应者

前端之家收集整理的这篇文章主要介绍了objective-c – 将App delegate设置为第一响应者前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试实现一个适用于我的应用程序的抖动识别.为此,我将以下代码添加到我的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的信息.

猜你在找的Xcode相关文章