0

I have already tried by this code but gesture not detect.

 UISwipeGestureRecognizer *mSwipeUpRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(up_downBtn_waytosalon)];
 [mSwipeUpRecognizer setDirection:UISwipeGestureRecognizerDirectionUp];
 [self.duration_distanceView addGestureRecognizer:mSwipeUpRecognizer];
Monika Patel
  • 2,287
  • 3
  • 20
  • 45

3 Answers3

0

First Off, you need to always pass the gesture recognizer to your selector, otherwise you can't determine the state of your gesture.

Other than that first check if that view has userInteractionEnabled to YES, I'm guessing that view doesn't get any user interaction.

M. Porooshani
  • 1,797
  • 5
  • 34
  • 42
0

Initialize swipe gesture like this:

UISwipeGestureRecognizer *mSwipeUpRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(up_downBtn_waytosalon:)];
      mSwipeUpRecognizer.direction = (UISwipeGestureRecognizerDirectionUp);
[self.duration_distanceView addGestureRecognizer:mSwipeUpRecognizer];

Implement the gesture action like this:

- (void) up_downBtn_waytosalon:(UISwipeGestureRecognizer *)sender {
  if ( sender.direction | UISwipeGestureRecognizerDirectionUp )
    NSLog(@"Its swipe up");
}

Hope this code helps.

Mrunal
  • 13,982
  • 6
  • 52
  • 96
  • don't copy paste another code if you do this just mention that I taken the code from here also http://stackoverflow.com/questions/8181774/how-to-recognize-swipe-in-all-4-directions – Anbu.Karthik Aug 25 '15 at 06:05
0

YOUR duration_distanceView view is imageView then add below line your code.

self.duration_distanceView.userInteractionEnabled = YES;

Try this code :

UISwipeGestureRecognizer *mSwipeUpRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(up_downBtn_waytosalon)];
self.duration_distanceView.userInteractionEnabled = YES;
 [mSwipeUpRecognizer setDirection:UISwipeGestureRecognizerDirectionUp];
 [self.duration_distanceView addGestureRecognizer:mSwipeUpRecognizer];
Kirit Modi
  • 23,155
  • 15
  • 89
  • 112