Created
May 6, 2011 04:36
-
-
Save chrishulbert/958448 to your computer and use it in GitHub Desktop.
How to make an iphone view controller detect left or right swipes
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)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