Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how detect swipe gesture direction?

Tags:

i need to detect direction of my swipe gesture and i've got problem with it. gesture is working, but i don't know how to detect direction. ...

swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(detectSwipe:)]; [swipeGesture setNumberOfTouchesRequired:1]; [swipeGesture setDirection:UISwipeGestureRecognizerDirectionDown | UISwipeGestureRecognizerDirectionUp]; [appView addGestureRecognizer:swipeGesture];  -(void)detectSwipe:(UISwipeGestureRecognizer *)recognizer {  switch (recognizer.direction) {     case UISwipeGestureRecognizerDirectionUp:         NSLog(@"smth1");         break;       case UISwipeGestureRecognizerDirectionDown:         NSLog(@"smth2");     default:         break; } } 

it's not working :/

like image 865
Tomasz Szulc Avatar asked Jan 11 '12 01:01

Tomasz Szulc


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.


1 Answers

Here is an example from one of my projects:

    // ...      UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipe:)];     swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;     [self.view addGestureRecognizer:swipeLeft];      UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self  action:@selector(didSwipe:)];     swipeRight.direction = UISwipeGestureRecognizerDirectionRight;     [self.view addGestureRecognizer:swipeRight];      UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc]  initWithTarget:self action:@selector(didSwipe:)];     swipeUp.direction = UISwipeGestureRecognizerDirectionUp;     [self.view addGestureRecognizer:swipeUp];      UISwipeGestureRecognizer *swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipe:)];     swipeDown.direction = UISwipeGestureRecognizerDirectionDown;     [self.view addGestureRecognizer:swipeDown];      // ...  - (void)didSwipe:(UISwipeGestureRecognizer*)swipe{      if (swipe.direction == UISwipeGestureRecognizerDirectionLeft) {         NSLog(@"Swipe Left");     } else if (swipe.direction == UISwipeGestureRecognizerDirectionRight) {         NSLog(@"Swipe Right");     } else if (swipe.direction == UISwipeGestureRecognizerDirectionUp) {         NSLog(@"Swipe Up");     } else if (swipe.direction == UISwipeGestureRecognizerDirectionDown) {         NSLog(@"Swipe Down");     } } 
like image 164
nemelianov Avatar answered Sep 25 '22 16:09

nemelianov