-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathE.m
168 lines (143 loc) · 5.09 KB
/
E.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#import "E.h"
#import "CGPointUtils.h"
#import <UIKit/UIGestureRecognizerSubclass.h>
#define kMinimumCheckMarkAngle 70
#define kMaximumCheckMarkAngle 110
#define kMinimumCheckMarkLength 20
@implementation E
//called when you touch the screen
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self.view];
lastPreviousPoint = point; //makes it equal to the point you are touching
lastCurrentPoint = point; //makes it equal to the point you are touching
lineLengthSoFar = 0.0f; // makes line length 0, f means float. i dont think you really need it.
x = 0;
}
//called when you move your finger
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesMoved:touches withEvent:event];
UITouch *touch = [touches anyObject];
CGPoint previousPoint = [touch previousLocationInView:self.view];
CGPoint currentPoint = [touch locationInView:self.view];
CGFloat angle2 = fabs(angleBetweenPoints(currentPoint, previousPoint));//check CGPointUtils.c for details
CGFloat angle3 = angleBetweenPoints(currentPoint, previousPoint);
lastPreviousPoint = previousPoint;
lastCurrentPoint = currentPoint;
//(currentPoint.x > previousPoint.x && x == 0 && angle2 < 30) ||
if((currentPoint.y < previousPoint.y && x == 0 && angle3 < 0 && angle3 > -70 )) //if moving straight right
{
lineLengthSoFar += distanceBetweenPoints(previousPoint, currentPoint);
if (lineLengthSoFar > 5)
x = 1; //change state
}
else if(currentPoint.y > previousPoint.y && angle2 > 70 && x == 0)
self.state = UIGestureRecognizerStateFailed;
else if((currentPoint.y < previousPoint.y && x == 0 && angle3 > 0 ))
self.state= UIGestureRecognizerStateFailed;
if (x == 1)
{
lineLengthSoFar = 0.0f;
x = 2;
}
if((x == 2 && currentPoint.y < previousPoint.y && angle3 > 0 && angle3 <= 90) || (x == 2 && currentPoint.x < previousPoint.x && angle2 < 20) || (x == 2 && currentPoint.y > previousPoint.y && angle3 > -50 && angle3 <0)) //if moving up left
{
lineLengthSoFar += distanceBetweenPoints(previousPoint, currentPoint);
if (lineLengthSoFar > 5)
x = 3;
}
else if((x == 2 && currentPoint.y > previousPoint.y && angle3 > 50 && angle3 <= 90) || (x== 2 && angle2 >80 && currentPoint.y > previousPoint.y ))
self.state = UIGestureRecognizerStateFailed;
if ( x == 3 )
{
lineLengthSoFar = 0.0f;
x = 4;
}
if(x == 4 && currentPoint.y > previousPoint.y && angle2 > 50) //if moving straight down
{
lineLengthSoFar += distanceBetweenPoints(previousPoint, currentPoint);
if (lineLengthSoFar > 10)
x = 5;
}
if (x == 5 )
{
lineLengthSoFar = 0.0f;
x = 6;
}
if(x == 6 && currentPoint.x > previousPoint.x && angle2 <30 )//3 <= 0 && angle3 > -60) //if moving up right
{
lineLengthSoFar += distanceBetweenPoints(previousPoint, currentPoint);
if (lineLengthSoFar > 5)
x = 7;
}
// if(currentPoint.x > previousPoint.x && x == 0 && angle3 <= 0 && angle3 > -70) //if moving straight right
// {
// lineLengthSoFar += distanceBetweenPoints(previousPoint, currentPoint);
// if (lineLengthSoFar > kMinimumCheckMarkLength)
// x = 1; //change state
// }
// else if(angle2 > 0 && currentPoint.x < previousPoint.x && x == 0)
// self.state = UIGestureRecognizerStateFailed;
//
// if (x == 1)
// {
// lineLengthSoFar = 0.0f;
// x = 2;
// }
//
//// if(x == 2 && currentPoint.y < previousPoint.y && angle3 > 20 && angle3 < 50) //if moving up left
//// {
//// lineLengthSoFar += distanceBetweenPoints(previousPoint, currentPoint);
//// if (lineLengthSoFar > kMinimumCheckMarkLength)
//// x = 3;
//// }
////
//// if ( x == 3 )
//// {
//// lineLengthSoFar = 0.0f;
//// x = 4;
//// }
//
// if(x == 2 && currentPoint.y > previousPoint.y && angle3 < -60 && angle3 >= -90) //if moving straight down
// {
// lineLengthSoFar += distanceBetweenPoints(previousPoint, currentPoint);
// if (lineLengthSoFar > kMinimumCheckMarkLength)
// x = 5;
// }
//
// if (x == 5 )
// {
// lineLengthSoFar = 0.0f;
// x = 6;
// }
//
// if(x == 6 && currentPoint.y < previousPoint.y && angle3 <= 0 && angle3 > -60) //if moving up right
// {
// lineLengthSoFar += distanceBetweenPoints(previousPoint, currentPoint);
// if (lineLengthSoFar > kMinimumCheckMarkLength)
// x = 7;
// }
// if (x == 7 && angle2 > 60 && currentPoint.y > previousPoint.y)
// self.state = UIGestureRecognizerStateFailed;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event //called when finger lift off screen
{
[super touchesEnded:touches withEvent:event];
if ((self.state == UIGestureRecognizerStatePossible) && x == 7)
self.state = UIGestureRecognizerStateRecognized; //recognized!
else
self.state = UIGestureRecognizerStateFailed;
x = -1;
}
- (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesCancelled:touches withEvent:event];
self.state = UIGestureRecognizerStateFailed;
x = -1;
}
- (void)reset {
[super reset];
x = -1;
}
@end