简体   繁体   中英

Swipe Gesture Recogniser not triggering?

I have a page view controller with five view controllers that get displayed.

I have tried adding these swipe gestures but they are not getting called?

   UISwipeGestureRecognizer *swipeGestureRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleRightSwipe:)];
swipeGestureRight.numberOfTouchesRequired = 1;
swipeGestureRight.direction = (UISwipeGestureRecognizerDirectionRight);
[self.scrollView addGestureRecognizer:swipeGestureRight];

UISwipeGestureRecognizer *swipeGestureLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleLeftSwipe:)];
swipeGestureLeft.numberOfTouchesRequired = 1;
swipeGestureLeft.direction = (UISwipeGestureRecognizerDirectionLeft);
[self.scrollView addGestureRecognizer:swipeGestureLeft];

Why arn't these being triggered and what can I do about it? My goal is to detect what direction the user swipes the page view controller.

add gesture to self.view

[self.view addGestureRecognizer:swipeGestureRight];

I hope it will work

Try this

  • Set the delegate of your UIGestureRecognizer and

  • Implement shouldRecognizeSimultaneouslyWithGestureRecognizer :

     -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{ return YES; } 
  • Implement shouldReceiveTouch :

     - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { return YES; } 

Hope this helps. Let me know if you still face the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM