0xdeadfa11
0xdeadfa11

Reputation: 63

Get the Direction of Swipe Before Scrolling a UIScrollView

Is there a way to get the direction of swipe before the scrolling the UIScrollView?

I tried to add swipe gesture but no luck.

Here is the event I want to handle. If I swipe fast sideways, left or right, and down-ish, I want it scroll else don't scroll. Also I want to get the interval of swipe. Is there a possible way to do those things? Thanks.

Upvotes: 0

Views: 362

Answers (1)

Niru Mukund Shah
Niru Mukund Shah

Reputation: 4733

You can use UISwipeGestureRecognizer control.Use UISwipeGestureRecognizerDirectionLeft for gettting Direction.

For that have look at this code below:

UISwipeGestureRecognizer *oneFingerSwipeLeft = [[[UISwipeGestureRecognizer alloc] 
                                                 initWithTarget:self 
                                                 action:@selector(oneFingerSwipeLeft:)] autorelease];
[oneFingerSwipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[[self view] addGestureRecognizer:oneFingerSwipeLeft]; 

In oneFingerSwipeLeft function you can have the direction. Follow the same process for right swipe.

Upvotes: 1

Related Questions