Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Mabdelwanis/914c788ffee286e28bf1ba292a1400cc to your computer and use it in GitHub Desktop.
Save Mabdelwanis/914c788ffee286e28bf1ba292a1400cc 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