Removing a view controller from UIPageViewController

前端 未结 12 2511
梦谈多话
梦谈多话 2020-11-28 19:22

It\'s odd that there\'s no straightforward way to do this. Consider the following scenario:

  1. You have a page view controller with 1 page.
  2. Add another p
12条回答
  •  眼角桃花
    2020-11-28 19:36

    This problem exists when you are trying to change viewControllers during swipe gesture animation between viewControllers. To solve this problem, i made a simple flag to discover when page view controller is during transition.

    - (void)pageViewController:(UIPageViewController *)pageViewController willTransitionToViewControllers:(NSArray *)pendingViewControllers {
        self.pageViewControllerTransitionInProgress = YES;
    }
    
    - (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed {
            self.pageViewControllerTransitionInProgress = NO;
    }
    

    And when i am trying to chenge view controller i am checking if there is transition in progress.

    - (void)setCurrentPage:(NSString *)newCurrentPageId animated:(BOOL)animated {
    
        if (self.pageViewControllerTransitionInProgress) {
            return;
        }
    
        [self.pageContentViewController setViewControllers:@[pageDetails] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:^(BOOL finished) {
        }
    
    }
    

提交回复
热议问题