Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect Swipe Gesture in iOS?

In my iPhone app, I require to recognize the swipe gesture made by the user on the view.

I want the swipe gestures to be recognized and perform a function on swipe.

I need that the view should horizontally slide and show another view as a user makes a swipe gesture.

What needs to be done?

How do I recognize it?

like image 303
Parth Bhatt Avatar asked Nov 25 '10 17:11

Parth Bhatt


People also ask

How do you detect swipe?

Swiping in touch is the act of quickly moving your finger across the touch surface in a certain direction.

How do you swipe gesture in iOS Swift?

A swipe gesture occurs when the user moves one or more fingers across the screen in a specific horizontal or vertical direction. Use the UISwipeGestureRecognizer class to detect swipe gestures. You can attach a gesture recognizer in one of these ways: Programmatically.

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

If You know how it works, but still need a quick example, here it is! (it will become handy at least for me, when I will need copy-paste example, without trying remembering it)

UISwipeGestureRecognizer *mSwipeUpRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(doSomething)];  [mSwipeUpRecognizer setDirection:(UISwipeGestureRecognizerDirectionUp | UISwipeGestureRecognizerDirectionDown | UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight)];  [[self view] addGestureRecognizer:mSwipeUpRecognizer]; 

and in .h file add:

<UIGestureRecognizerDelegate> 
like image 111
Guntis Treulands Avatar answered Sep 22 '22 17:09

Guntis Treulands