Created
May 7, 2017 23:51
-
-
Save jen2/361ab58f4c7de041cd1a4d1d24daeb0d to your computer and use it in GitHub Desktop.
"Make a Custom UIGestureRecognizer in Objective-C" Touches Moved Method.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event | |
{ | |
[super touchesMoved:touches withEvent:event]; //A | |
if ((self.state == UIGestureRecognizerStateFailed) || (self.state == UIGestureRecognizerStateRecognized)) { //B | |
return; | |
} | |
UIView *superView = [self.view superview]; //C | |
CGPoint currentPoint = [touches.anyObject locationInView:superView]; | |
CGPoint previousPoint = [touches.anyObject previousLocationInView:superView]; | |
if ((self.strokePart == 0) && ((currentPoint.x — self.firstTap.x) > 20.00) && (currentPoint.x > previousPoint.x) && | |
((currentPoint.y — self.firstTap.y) <= self.strokePrecision)) { //D | |
NSLog(@”Stroke part 1 complete”); //E | |
self.strokePart = 1; //F | |
} else if ((self.strokePart == 1) && (currentPoint.x < previousPoint.x) && (currentPoint.y > previousPoint.y)) { //G | |
NSLog(@”Stroke part 2 complete”); | |
self.strokePart = 2; //H | |
} else if ((self.strokePart == 2) && (currentPoint.x > previousPoint.x) && ((currentPoint.y — previousPoint.y) <= | |
self.strokePrecision)) { //I | |
self.strokePart = 3; | |
self.state = UIGestureRecognizerStateRecognized; //J | |
NSLog(@”Gesture Recognized!”); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment