forked from dayanch96/ShowMyTouches
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTweak.x
89 lines (73 loc) · 3.76 KB
/
Tweak.x
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#import <UIKit/UIKit.h>
#import "SMTPrefs/SMTUserDefaults.h"
#define kTouchViewKey @selector(ShowMyTouches_TouchView)
@interface RPScreenRecorder : NSObject
- (BOOL)isRecording;
+ (instancetype)sharedRecorder;
@end
%hook UIApplication
- (void)sendEvent:(UIEvent *)event {
%orig;
if (!smtBool(@"enable")) {
return;
}
if (smtBool(@"recording") && ![[%c(RPScreenRecorder) sharedRecorder] isRecording]) {
return;
}
if (event.type == UIEventTypeTouches) {
NSSet *touches = [event allTouches];
for (UITouch *touch in touches) {
CGPoint touchPoint = [touch locationInView:nil];
UIView *touchView = nil;
if (touch.phase == UITouchPhaseBegan) {
if (!touchView) {
NSData *touchData = [[SMTUserDefaults standardUserDefaults] objectForKey:@"touchColor"];
UIColor *touchColor = [NSKeyedUnarchiver unarchivedObjectOfClass:[UIColor class] fromData:touchData error:nil];
NSData *borderData = [[SMTUserDefaults standardUserDefaults] objectForKey:@"borderColor"];
UIColor *borderColor = [NSKeyedUnarchiver unarchivedObjectOfClass:[UIColor class] fromData:borderData error:nil];
CGFloat size = [[SMTUserDefaults standardUserDefaults] floatForKey:@"touchSize"];
CGFloat cornerRadius = [[SMTUserDefaults standardUserDefaults] floatForKey:@"touchRadius"];
CGFloat borderWidth = [[SMTUserDefaults standardUserDefaults] floatForKey:@"borderWidth"];
touchView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, size, size)];
touchView.center = CGPointMake(touchPoint.x, touchPoint.y);
touchView.backgroundColor = touchColor;
touchView.layer.cornerRadius = cornerRadius;
touchView.layer.borderColor = borderColor.CGColor;
touchView.layer.borderWidth = borderWidth;
touchView.clipsToBounds = (size / 2) <= cornerRadius;
touchView.userInteractionEnabled = NO;
dispatch_async(dispatch_get_main_queue(), ^{
[touch.window addSubview:touchView];
});
objc_setAssociatedObject(touch, kTouchViewKey, touchView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
}
if (touch.phase == UITouchPhaseMoved) {
touchView = objc_getAssociatedObject(touch, kTouchViewKey);
if (touchView) {
dispatch_async(dispatch_get_main_queue(), ^{
touchView.center = CGPointMake(touchPoint.x, touchPoint.y);
});
}
}
if (touch.phase == UITouchPhaseEnded || touch.phase == UITouchPhaseCancelled) {
touchView = objc_getAssociatedObject(touch, kTouchViewKey);
if (touchView) {
if (touch.tapCount > 1) {
[touchView removeFromSuperview];
} else {
CGFloat duration = [[SMTUserDefaults standardUserDefaults] floatForKey:@"duration"];
[UIView animateWithDuration:duration delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations:^{
touchView.alpha = 0.0;
touchView.transform = CGAffineTransformMakeScale(1.5, 1.5);
} completion:^(BOOL finished) {
[touchView removeFromSuperview];
}];
}
objc_setAssociatedObject(touch, kTouchViewKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
}
}
}
}
%end