Skip to content

Instantly share code, notes, and snippets.

@jontelang
Created April 15, 2015 09:01
Show Gist options
  • Save jontelang/3d82421ae74e452c885a to your computer and use it in GitHub Desktop.
Save jontelang/3d82421ae74e452c885a to your computer and use it in GitHub Desktop.
void KTouchPointerWindowInstall();
void KTouchPointerWindowUninstall();
static BOOL installed;
void KTouchPointerWindowInstall()
{
if (!installed) {
installed = YES;
Class _class = [UIWindow class];
Method orig = class_getInstanceMethod(_class, sel_registerName("sendEvent:"));
Method my = class_getInstanceMethod(_class, sel_registerName("k_sendEvent:"));
method_exchangeImplementations(orig, my);
}
}
void KTouchPointerWindowUninstall()
{
if (installed) {
installed = NO;
Class _class = [UIWindow class];
Method orig = class_getInstanceMethod(_class, sel_registerName("sendEvent:"));
Method my = class_getInstanceMethod(_class, sel_registerName("k_sendEvent:"));
method_exchangeImplementations(orig, my);
NSArray *windows = [[UIApplication sharedApplication] windows];
[windows makeObjectsPerformSelector:@selector(setNeedsDisplay)];
}
}
@interface UIWindow (KTouchPointerWindow)
@end
@implementation UIWindow (KTouchPointerWindow)
-(void) k_sendEvent:(UIEvent *)event
{
NSMutableSet *began = nil;
NSMutableSet *moved = nil;
NSMutableSet *ended = nil;
NSMutableSet *cancelled = nil;
for (UITouch *touch in [event allTouches]) {
switch (touch.phase) {
case UITouchPhaseBegan:
if (!began) {
began = [NSMutableSet set];
}
[began addObject:touch];
break;
case UITouchPhaseEn....
...
...
}
}
NSLog(@"event");
[self k_sendEvent:event];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment