|
|
//
|
|
|
// UIGestureRecognizer+AutoTrack.m
|
|
|
// UITapGestureRecognizer+AutoTrack.m
|
|
|
// YHEventReport
|
|
|
//
|
|
|
// Created by 孙凯 on 2017/9/28.
|
|
|
// Created by 孙凯 on 2017/10/11.
|
|
|
// Copyright © 2017年 YOHO. All rights reserved.
|
|
|
//
|
|
|
|
|
|
#import "UIGestureRecognizer+AutoTrack.h"
|
|
|
#import "UITapGestureRecognizer+AutoTrack.h"
|
|
|
#import "YHSwizzle.h"
|
|
|
#import <objc/runtime.h>
|
|
|
#import <objc/message.h>
|
...
|
...
|
@@ -14,13 +14,7 @@ |
|
|
#import "YHEventReport.h"
|
|
|
#import "YH_EventCollector.h"
|
|
|
|
|
|
@interface UIGestureRecognizer ()<UIGestureRecognizerDelegate>
|
|
|
|
|
|
@property(nullable,nonatomic,weak) id <UIGestureRecognizerDelegate> my_delegate;
|
|
|
|
|
|
@end
|
|
|
|
|
|
@implementation UIGestureRecognizer (AutoTrack)
|
|
|
@implementation UITapGestureRecognizer (AutoTrack)
|
|
|
|
|
|
#pragma mark - 属性
|
|
|
- (void)setYh_viewId:(NSString *)yh_viewId{
|
...
|
...
|
@@ -31,16 +25,6 @@ |
|
|
return objc_getAssociatedObject(self, @selector(yh_viewId));
|
|
|
}
|
|
|
|
|
|
- (id)my_delegate
|
|
|
{
|
|
|
return objc_getAssociatedObject(self, _cmd);
|
|
|
}
|
|
|
|
|
|
- (void)setMy_delegate:(id)my_delegate
|
|
|
{
|
|
|
objc_setAssociatedObject(self, @selector(my_delegate), my_delegate, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
|
}
|
|
|
|
|
|
#pragma mark - load
|
|
|
+ (void)startTrack{
|
|
|
static dispatch_once_t onceToken;
|
...
|
...
|
@@ -49,7 +33,6 @@ |
|
|
SEL selectors[] = {
|
|
|
@selector(initWithTarget:action:),
|
|
|
@selector(addTarget:action:),
|
|
|
@selector(setDelegate:),
|
|
|
};
|
|
|
|
|
|
for (NSUInteger index = 0; index < sizeof(selectors) / sizeof(SEL); ++index) {
|
...
|
...
|
@@ -71,23 +54,10 @@ |
|
|
}
|
|
|
|
|
|
#pragma mark - hook API
|
|
|
-(void)yher_setDelegate:(id<UIGestureRecognizerDelegate>)delegate
|
|
|
{
|
|
|
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].buttonPerformanceTrackEnable && ([delegate isKindOfClass:[UIViewController class]] || [delegate isKindOfClass:[UIImageView class]] || [delegate isKindOfClass:[UILabel class]])) {
|
|
|
if (![delegate isKindOfClass:[self class]]) {
|
|
|
[self setMy_delegate:delegate];
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
[self yher_setDelegate:delegate];
|
|
|
|
|
|
}
|
|
|
|
|
|
- (instancetype)yher_initWithTarget:(nullable id)target action:(nullable SEL)action
|
|
|
{
|
|
|
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].buttonPerformanceTrackEnable && ([target isKindOfClass:[UIViewController class]] || [target isKindOfClass:[UIImageView class]] || [target isKindOfClass:[UILabel class]])) {
|
|
|
[UIGestureRecognizer yher_exchangeSelector:action target:target toSelector:@selector(yher_gestureRecognizerDidTouch_cmd:)];
|
|
|
[self setDelegate:self];
|
|
|
if (([target isKindOfClass:[UIViewController class]] || [target isKindOfClass:[UIImageView class]] || [target isKindOfClass:[UILabel class]])) {
|
|
|
[UITapGestureRecognizer yher_exchangeSelector:action target:target toSelector:@selector(yher_gestureRecognizerDidTouch_cmd:)];
|
|
|
}
|
|
|
return [self yher_initWithTarget:target action:action];
|
|
|
}
|
...
|
...
|
@@ -95,22 +65,26 @@ |
|
|
- (void)yher_addTarget:(id)target action:(SEL)action
|
|
|
{
|
|
|
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].buttonPerformanceTrackEnable && ([target isKindOfClass:[UIViewController class]] || [target isKindOfClass:[UIImageView class]] || [target isKindOfClass:[UILabel class]])) {
|
|
|
[UIGestureRecognizer yher_exchangeSelector:action target:target toSelector:@selector(yher_gestureRecognizerDidTouch_cmd:)];
|
|
|
[self setDelegate:self];
|
|
|
[UITapGestureRecognizer yher_exchangeSelector:action target:target toSelector:@selector(yher_gestureRecognizerDidTouch_cmd:)];
|
|
|
}
|
|
|
|
|
|
|
|
|
[self yher_addTarget:target action:action];
|
|
|
}
|
|
|
|
|
|
#pragma mark - action
|
|
|
- (void)yher_gestureRecognizerDidTouch_cmd:(UIGestureRecognizer*)sender
|
|
|
{
|
|
|
|
|
|
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].buttonPerformanceTrackEnable && ([sender.view isKindOfClass:[UIImageView class]] || [sender.view isKindOfClass:[UILabel class]])) {
|
|
|
[[YH_EventCollector sharedInstance] timeEventEndWithUIGestureRecognizer:sender];
|
|
|
if (([sender.view isKindOfClass:[UIImageView class]] || [sender.view isKindOfClass:[UILabel class]])) {
|
|
|
[[YH_EventCollector sharedInstance] timeEventStartWithUIGestureRecognizer:sender];
|
|
|
}
|
|
|
|
|
|
|
|
|
[self yher_gestureRecognizerDidTouch_cmd:sender];
|
|
|
|
|
|
|
|
|
if (([sender.view isKindOfClass:[UIImageView class]] || [sender.view isKindOfClass:[UILabel class]])) {
|
|
|
[[YH_EventCollector sharedInstance] timeEventEndWithUIGestureRecognizer:sender];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#pragma mark - hook func
|
...
|
...
|
@@ -132,60 +106,4 @@ |
|
|
class_replaceMethod(originalClass,originalSelector,swizzledIMP,swizzledType);
|
|
|
}
|
|
|
|
|
|
#pragma mark - UIGestureRecognizerDelegate
|
|
|
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
|
|
|
{
|
|
|
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].buttonPerformanceTrackEnable) {
|
|
|
[[YH_EventCollector sharedInstance] timeEventStartWithUIGestureRecognizer:self];
|
|
|
}
|
|
|
|
|
|
if (self.my_delegate && [self.my_delegate respondsToSelector:@selector(gestureRecognizerShouldBegin:)]) {
|
|
|
return [self.my_delegate gestureRecognizerShouldBegin:gestureRecognizer];
|
|
|
}
|
|
|
return YES;
|
|
|
}
|
|
|
|
|
|
|
|
|
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
|
|
|
{
|
|
|
if (self.my_delegate && [self.my_delegate respondsToSelector:@selector(gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:)]) {
|
|
|
return [self.my_delegate gestureRecognizer:gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:otherGestureRecognizer];
|
|
|
}
|
|
|
|
|
|
return YES;
|
|
|
}
|
|
|
|
|
|
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRequireFailureOfGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
|
|
|
{
|
|
|
if (self.my_delegate && [self.my_delegate respondsToSelector:@selector(gestureRecognizer:shouldRequireFailureOfGestureRecognizer:)]) {
|
|
|
return [self.my_delegate gestureRecognizer:gestureRecognizer shouldRequireFailureOfGestureRecognizer:otherGestureRecognizer];
|
|
|
}
|
|
|
return YES;
|
|
|
}
|
|
|
|
|
|
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
|
|
|
{
|
|
|
if (self.my_delegate && [self.my_delegate respondsToSelector:@selector(gestureRecognizer:shouldBeRequiredToFailByGestureRecognizer:)]) {
|
|
|
return [self.my_delegate gestureRecognizer:gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:otherGestureRecognizer];
|
|
|
}
|
|
|
return YES;
|
|
|
}
|
|
|
|
|
|
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
|
|
|
{
|
|
|
if (self.my_delegate && [self.my_delegate respondsToSelector:@selector(gestureRecognizer:shouldReceiveTouch:)]) {
|
|
|
return [self.my_delegate gestureRecognizer:gestureRecognizer shouldReceiveTouch:touch];
|
|
|
}
|
|
|
return YES;
|
|
|
}
|
|
|
|
|
|
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceivePress:(UIPress *)press
|
|
|
{
|
|
|
if (self.my_delegate && [self.my_delegate respondsToSelector:@selector(gestureRecognizer:shouldReceivePress:)]) {
|
|
|
return [self.my_delegate gestureRecognizer:gestureRecognizer shouldReceivePress:press];
|
|
|
}
|
|
|
return YES;
|
|
|
}
|
|
|
|
|
|
|
|
|
@end |
...
|
...
|
|