如何在全球范围内跟踪UITouches?

时间:2012-01-30 23:26:46

标签: ios

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

2 个答案:

答案 0 :(得分: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

将此子类的名称传递给UIApplicationMain中的main.m

#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]));
    }
}

答案 1 :(得分:0)

我认为这篇文章有助DETECTING TAPS AND EVENTS ON UIWEBVIEW – THE RIGHT WAY。您可以使用相同的技术。