I am currently facing a scenario that I am using a UIPageViewController
on a view & I want the right swipe gesture to work when user swipe right side from index value 0
, so I am trying to add a right swipe gesture to UIPageViewController
by the following code:
UISwipeGestureRecognizer *rightRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightSwipeHandle:)];
rightRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
[rightRecognizer setNumberOfTouchesRequired:1];
//Edit 1
[self.pageViewController.view addGestureRecognizer:rightRecognizer];
but, while I am adding gesture to pageviewcontroller
I am getting following error message (Solved by @Lyndsey Scott answer)
no visible interface uipageviewcontroller declares the selector addgesturerecognizer
Can anyone guide me that how can I implement the right swipe in this pageViewController
Edit 1: Replaced the code provided by @Lyndsey Scott, removed the error, but problem still exists that I am not able to trigger that swipe event.
You have to the gesture to the
UIPageViewController
's view:Edit in response to your edit:
The swipe gesture won't work if you haven't implemented any
UIGestureRecognizerDelegate
methods to allow for theUIPageViewController
's swipe gesture and your swipe gesture to be recognized simultaneously. Right now, your swipe is essentially being blocked by the page controller's gesture. You could change that by implementing theUIGestureRecognizerDelegate
, settingrightRecognizer.delegate = self;
, and overridinggestureRecognizer: shouldRecognizeSimultaneouslyWithGestureRecognizer:otherGestureRecognizer
such that it returns true in the case that both gesture recognizers are triggered.But if you want the page to flip and your gesture to be recognized at the time of that page flip, adding the extra swipe gesture is unnecessary since you can simply trigger your method upon page turn; for example in
pageViewController:didFinishAnimating:previousViewControllers: transitionCompleted:
.