如何监听app所有事件
1, 修改main方法
int main(int argc, char * argv[]) { @autoreleasepool { return UIApplicationMain(argc, argv, NSStringFromClass([AppDelegate class]), NSStringFromClass([AppDelegate class])); } }
2, 让 AppDelegate继承自UIApplication,原来是继承自UIResponder
@interface AppDelegate : UIApplication <UIApplicationDelegate>
3, 在AppDelegate中实现 sendEvent方法
- (void)sendEvent:(UIEvent *)event { [super sendEvent:event]; NSSet *allTouches = [event allTouches]; if (allTouches.count > 0) { UITouchPhase phase = ((UITouch *)[allTouches anyObject]).phase; if (phase == UITouchPhaseBegan) { NSLog(@"TouchPhaseBegan"); } } }