2012-01-30 56 views
1

我想设置一个全局UITouch处理程序来调试所有正在通过系统的UITouch事件以及哪个视图是目标等。我该如何实现这一点?如何跟踪全球UITouches?

回答

2

使UIApplication一个子类覆盖sendEvent:方法:

@interface MyApplication : UIApplication 
@end 

@implementation MyApplication 

- (void)sendEvent:(UIEvent *)event { 
    if (event.type == UIEventTypeTouches) { 
     NSLog(@"Touch event: %@", event); 
    } 
    [super sendEvent:event]; 
} 

@end 

main.m通过这个子类UIApplicationMain名称:

#import <UIKit/UIKit.h> 
#import "AppDelegate.h" 
#import "MyApplication.h" 

int main(int argc, char *argv[]) 
{ 
    @autoreleasepool { 
     return UIApplicationMain(argc, argv, 
      NSStringFromClass([MyApplication class]), 
      NSStringFromClass([AppDelegate class])); 
    } 
}