-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgesture.m
118 lines (100 loc) · 4.14 KB
/
gesture.m
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#import <SpringBoard/SpringBoard.h>
#import <CaptainHook/CaptainHook.h>
CHDeclareClass(UIStatusBar);
enum TWTweetComposeViewControllerResult {
TWTweetComposeViewControllerResultCancelled,
TWTweetComposeViewControllerResultDone
};
typedef enum TWTweetComposeViewControllerResult TWTweetComposeViewControllerResult;
typedef void (^TWTweetComposeViewControllerCompletionHandler)(TWTweetComposeViewControllerResult result);
@interface TWTweetComposeViewController : UIViewController
@property(nonatomic, copy) TWTweetComposeViewControllerCompletionHandler completionHandler;
@end
// press home button
CHDeclareMethod(0, void, UIStatusBar, swipeLeft)
{
struct GSEventRecord record;
memset(&record, 0, sizeof(record));
record.type = kGSEventMenuButtonDown;
record.timestamp = GSCurrentEventTimestamp();
GSSendSystemEvent(&record);
record.type = kGSEventMenuButtonUp;
GSSendSystemEvent(&record);
}
// press home button twice
CHDeclareMethod(0, void, UIStatusBar, swipeRight)
{
[self performSelector:@selector(swipeLeft) withObject:nil afterDelay:0.05f];
[self performSelector:@selector(swipeLeft) withObject:nil afterDelay:0.10f];
}
// tweet
static UIWindow *_sharedTweetWindow = nil;
CHDeclareMethod(1, void, UIStatusBar, doubleTapped, UIGestureRecognizer *, recognizer)
{
if (recognizer.state == UIGestureRecognizerStateEnded) {
if (_sharedTweetWindow == nil) {
_sharedTweetWindow = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
}
if (_sharedTweetWindow.rootViewController == nil) {
TWTweetComposeViewController *tweetController = [[TWTweetComposeViewController alloc] init];
tweetController.completionHandler = ^(TWTweetComposeViewControllerResult result) {
[_sharedTweetWindow resignFirstResponder];
_sharedTweetWindow.hidden = YES;
_sharedTweetWindow.rootViewController = nil;
};
_sharedTweetWindow.rootViewController = tweetController;
[tweetController release];
}
// update orientation
int orientation = CHIvar(self, _orientation, int);
[_sharedTweetWindow _updateToInterfaceOrientation:orientation animated:NO];
// do not make key window or table view won't scroll again when status bar touched
[_sharedTweetWindow becomeFirstResponder];
_sharedTweetWindow.hidden = NO;
}
}
CHDeclareMethod(0, void, UIStatusBar, setGesture)
{
// double tap
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] init];
tapRecognizer.numberOfTapsRequired = 2;
tapRecognizer.delaysTouchesBegan = YES;
tapRecognizer.delaysTouchesEnded = YES;
[tapRecognizer addTarget:self action:@selector(doubleTapped:)];
[self addGestureRecognizer:tapRecognizer];
[tapRecognizer release];
// swipe left
UISwipeGestureRecognizer *swipeLeftRecognizer = [[UISwipeGestureRecognizer alloc] init];
swipeLeftRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
swipeLeftRecognizer.delaysTouchesBegan = YES;
swipeLeftRecognizer.delaysTouchesEnded = YES;
[swipeLeftRecognizer addTarget:self action:@selector(swipeLeft)];
[self addGestureRecognizer:swipeLeftRecognizer];
[swipeLeftRecognizer release];
// swipe right
UISwipeGestureRecognizer *swipeRightRecognizer = [[UISwipeGestureRecognizer alloc] init];
swipeRightRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
swipeRightRecognizer.delaysTouchesBegan = YES;
swipeRightRecognizer.delaysTouchesEnded = YES;
[swipeRightRecognizer addTarget:self action:@selector(swipeRight)];
[self addGestureRecognizer:swipeRightRecognizer];
[swipeRightRecognizer release];
}
CHOptimizedMethod(1, super, id, UIStatusBar, initWithFrame, CGRect, frame)
{
CHSuper(1, UIStatusBar, initWithFrame, frame);
[self performSelector:@selector(setGesture) withObject:nil];
return self;
}
CHOptimizedMethod(2, super, id, UIStatusBar, initWithFrame, CGRect, frame, showForegroundView, UIView, view)
{
CHSuper(2, UIStatusBar, initWithFrame, frame, showForegroundView, view);
[self performSelector:@selector(setGesture) withObject:nil];
return self;
}
CHConstructor
{
CHLoadLateClass(UIStatusBar);
CHHook(1, UIStatusBar, initWithFrame);
CHHook(2, UIStatusBar, initWithFrame, showForegroundView);
}