Skip to content

Instantly share code, notes, and snippets.

@xoebus
Created March 25, 2010 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save xoebus/343792 to your computer and use it in GitHub Desktop.
Save xoebus/343792 to your computer and use it in GitHub Desktop.
Vertical and Horizontal Swipes for iPhone
UITouch *touch = [touches anyObject];
CGPoint currentPosition = [touch locationInView:[self view]];
CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x);
CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y);
if (deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance) {
[label setText:@"Horizontal swipe detected"];
[self performSelector:@selector(eraseText) withObject:nil afterDelay:2];
} else if (deltaY >= kMinimumGestureLength && deltaX <= kMaximumVariance) {
[label setText:@"Vertical swipe detected"];
[self performSelector:@selector(eraseText) withObject:nil afterDelay:2];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment