Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper Swipe gesture recognizer iOS

I haven't been able to find a tutorial on how to properly setup a gesture recognizer for iOS. I need to detect swipe up & down, and the callbacks for them.

Any help, appreciated. Thanks.

like image 621
iamruskie Avatar asked Sep 14 '12 09:09

iamruskie


People also ask

Which controller is used to add swipe gesture in iOS?

UIPageViewController can handle swipes and view transitions.

What is swipe gesture on iPhone?

Swipe right or left along the bottom edge of the screen to quickly switch between open apps. See Switch between open apps on iPhone.


1 Answers

You need two recognizers, one for swiping up, and the other for swiping down:

UISwipeGestureRecognizer* swipeUpGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeUpFrom:)];
swipeUpGestureRecognizer.direction = UISwipeGestureRecognizerDirectionUp;

and for the handler:

- (void)handleSwipeUpFrom:(UIGestureRecognizer*)recognizer {

}

Finally, you add it to your view:

[view addGestureRecognizer:swipeUpGestureRecognizer];

The same for the other direction (just change all the Ups to Downs).

like image 95
sergio Avatar answered Jan 30 '23 17:01

sergio