FORGestureTrackDisplay 0.1.0

FORGestureTrackDisplay 0.1.0

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最新发布2017年5月

XcodeYang 维护。



  • 作者
  • Yang Zhiping

FORGestureTrackDisplay 是一个调试工具,用于在用户触摸屏幕时显示和跟踪所有类型的手势。

untitled

使用方法

第一种方法(手动)

这种方式,只有 appdelegate.window 可以跟踪手势。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    [self.window startTracking];
    
    return YES;
}

第二种方法(自动)

我强烈推荐这种方式来自动跟踪所有窗口中的手势。

@implementation NSObject (Runtime)

+ (void)swizzleInstanceMethodWithOriginSel:(SEL)oriSel swizzledSel:(SEL)swiSel {
    Method originAddObserverMethod = class_getInstanceMethod(self, oriSel);
    Method swizzledAddObserverMethod = class_getInstanceMethod(self, swiSel);
    
    [self swizzleMethodWithOriginSel:oriSel oriMethod:originAddObserverMethod swizzledSel:swiSel swizzledMethod:swizzledAddObserverMethod class:self];
}

+ (void)swizzleMethodWithOriginSel:(SEL)oriSel
                         oriMethod:(Method)oriMethod
                       swizzledSel:(SEL)swizzledSel
                    swizzledMethod:(Method)swizzledMethod
                             class:(Class)cls {
    BOOL didAddMethod = class_addMethod(cls, oriSel, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod));
    
    if (didAddMethod) {
        class_replaceMethod(cls, swizzledSel, method_getImplementation(oriMethod), method_getTypeEncoding(oriMethod));
    } else {
        method_exchangeImplementations(oriMethod, swizzledMethod);
    }
}
@end
@implementation UIWindow (Runtime)

+ (void)load {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        [self swizzleInstanceMethodWithOriginSel:@selector(becomeKeyWindow) swizzledSel:@selector(xy_becomeKeyWindow)];
        [self swizzleInstanceMethodWithOriginSel:@selector(resignKeyWindow) swizzledSel:@selector(xy_resignKeyWindow)];
    });
}

- (void)xy_becomeKeyWindow
{
    [self xy_becomeKeyWindow];
    [self startTracking];
}

- (void)xy_resignKeyWindow
{
    [self xy_resignKeyWindow];
    [self endTracking];
}
@end