Skip to content

Instantly share code, notes, and snippets.

@chrishulbert
Created May 6, 2011 04:36
Show Gist options
  • Save chrishulbert/958448 to your computer and use it in GitHub Desktop.
Save chrishulbert/958448 to your computer and use it in GitHub Desktop.
How to make an iphone view controller detect left or right swipes
- (void)swipeLeft {
NSLog(@"Left!");
}
- (void)swipeRight {
NSLog(@"Right!");
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
// Set up the swipe recogniser
UISwipeGestureRecognizer *leftSwiper = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeft)];
leftSwiper.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:leftSwiper];
[leftSwiper release];
UISwipeGestureRecognizer *rightSwiper = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRight)];
rightSwiper.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:rightSwiper];
[rightSwiper release];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment