1
votes

I have a UIPageViewController with datasource which dynamically changes -

viewControllerAfterViewController

and

viewControllerBeforeViewController

return nil if data is not ready yet, and return view controller if it is ready. If i try to turn page left multiple times quickly at some point viewControllerAfterViewController is not being called any more.

What can be the problem? I suppose UIPageViewController thinks that it knows everything and nothing has changed so it does not call that method, is it right? How can I 'reset' this cache?

I use curl transition style, and this seems to happen only in landscape mode.

1

1 Answers

3
votes

I ended up using my own swipe gestures.

  1. First remove existing swipe gestures from UIPageViewController

    for (UIGestureRecognizer * recognizer in _pageViewController.gestureRecognizers) {
        recognizer.enabled = NO;
    }
    
  2. Then add your own swipe gesture recognizers to UIPageViewController

    UISwipeGestureRecognizer * rightRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleRightSwipe:)];
    [rightRecognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
    [_pageViewController.view addGestureRecognizer:rightRecognizer];
    
    UISwipeGestureRecognizer * leftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleLeftSwipe:)];
    [leftRecognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
    [_pageViewController.view addGestureRecognizer:leftRecognizer];
    
    - (void) handleRightSwipe: (id) sender {
    // your swipe handler here 
    // note that you need  to call didFinishAnimating manually now
    
    // manually calculate next/prev view controller, also you should consider orientation too
     UIViewController * nextController = [_modelController pageViewController:_pageViewController viewControllerAfterViewController:existingController];
    
    
    __weak typeof(self) weakSelf = self;
    __weak UIPageViewController * wController = _pageViewController;
    [_pageViewController setViewControllers:@[nextController] direction:
        UIPageViewControllerNavigationDirectionForward animated:YES completion:^(BOOL completed){
            [weakSelf pageViewController:wController didFinishAnimating:YES previousViewControllers:@[existingController] transitionCompleted:YES];
        }];
      }
     }
    

Also, you may try not to remove existing swipe gestures, it looks like it does not call your custom swipe gestures if existing recognizers trigger, this way you also have nice animation when you drag corner of page (it will be lost if you remove all recognizers).