Reputation: 181
I'm attempting to dismiss a UIPageViewController which is presented modally when the user scrolls past the last page. Is there a way to tell when this happens? viewControllerAfterViewController is called when the last view controller is shown.
Edit: I've also tried to add UISwipeGestureRecognizers but they are not being called. I think this is because the UIPageViewController's gesture recognizer's disable them.
Upvotes: 3
Views: 1847
Reputation: 1429
UIViewController:viewWillAppear:animated
will get called when the user swipes to that page. So you could add a dummy last page, and dismiss the pageViewController when that gets called.
Upvotes: 1
Reputation: 7252
You didn't indicate what language you're using so here it is in Objective-C
You should have your viewControllerAfterViewController
method set up to look something like this:
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
NSUInteger index = [(CustomViewController *)viewController index];
index++;
if (index == 10) { // the number of controllers you have.
return nil;
}
return [self viewControllerAtIndex:index]; // you view controller creation method.
}
viewControllerAfterViewController
is called whenever a user attempts to swipe through your pages. If the user tries to go beyond the last page, this method should return nil. When that happens, dismiss the pageViewController
.
Upvotes: 0