Here's all you have to do to gather swipe input from your iphone screen:
UISwipeGestureRecognizer * leftSwipe = [[ UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipe:)];
[view addGestureRecognizer:leftSwipe];
leftSwipe.direction = UISwipeGestureRecognizerDirectionLeft;
Set up several of these in your view controller initialization method, then implement the handler:
- (void) didSwipe: (UISwipeGestureRecognizer*) sender {
UISwipeGestureRecognizerDirection direction = sender.direction;
switch( direction ) {
case UISwipeGestureRecognizerDirectionLeft: NSLog(@"left");
break;
case UISwipeGestureRecognizerDirectionRight: NSLog(@"right");
break;
}
}
This is excerpted from this excellent youtube tutorial:
http://www.youtube.com/watch?v=5Ou8Oqhngm8
No comments:
Post a Comment