-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathNine.m
100 lines (76 loc) · 2.73 KB
/
Nine.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
#import "CGPointUtils.h"
#import <UIKit/UIGestureRecognizerSubclass.h>
#import "Nine.h"
#define kMinimumCheckMarkLength 20
@implementation Nine
//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;
if(x == 0 && currentPoint.x < previousPoint.x && angle2 < 20) //if moving straight left
{
lineLengthSoFar += distanceBetweenPoints(previousPoint, currentPoint);
if (lineLengthSoFar > 5)
x = 1; //change state
}
if (x == 1 )
{
lineLengthSoFar = 0.0f;
x = 2;
}
if(x == 2 && currentPoint.y < previousPoint.y && angle3 < -10 && angle3 > -60) //if moving up right
{
lineLengthSoFar += distanceBetweenPoints(previousPoint, currentPoint);
if (lineLengthSoFar > 20)
x = 3;
}
else if(currentPoint.y > previousPoint.y && angle2 > 60 && x == 2)
self.state = UIGestureRecognizerStateFailed;
if (x == 3 )
{
lineLengthSoFar = 0.0f;
x = 4;
}
if(x == 4 && currentPoint.y > previousPoint.y && angle3 >= -90 && angle3 < -50) //if moving straight down
{
lineLengthSoFar += distanceBetweenPoints(previousPoint, currentPoint);
if (lineLengthSoFar > kMinimumCheckMarkLength)
x = 5;
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event //called when finger lift off screen
{
[super touchesEnded:touches withEvent:event];
if ((self.state == UIGestureRecognizerStatePossible) && x == 5)
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