Activate UIPageViewController Delay Page Change

I am developing an application using the UIPageViewController. I noticed that if I change several pages too quickly, this will cause several problems at runtime.

Is there a way to set the delay (e.g. 2 or 3 milliseconds) between two page changes? Thanks in advance.

************ DETAILED RESPONSE **************

The solution is this:

-(void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed{ if(completed) { [pageViewController.view setUserInteractionEnabled:NO]; [self performSelector:@selector(enableUserInteraction) withObject:nil afterDelay:0.2]; } } -(void)enableUserInteraction{ [self.view setUserInteractionEnabled:YES]; } 
+4
source share
2 answers

In your animation block, set userInteraction = NO until the animation ends. This means that the user will not be able to interact with the screen and thereby change the page until it completes the animation.

+3
source

I put it in pageViewController: willTransitionToViewControllers: and used dispatch_after . With this solution, the user cannot quickly scroll 2-3 times, as in pageViewController: didFinishAnimating: previousViewControllers: transitionCompleted:

 - (void)pageViewController:(UIPageViewController *)pageViewController willTransitionToViewControllers:(NSArray<UIViewController *> *)pendingViewControllers { pageViewController.view.userInteractionEnabled = NO; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ pageViewController.view.userInteractionEnabled = YES; }); } 
0
source

All Articles