UIPageViewController transition 'Unbalanced calls to begin/end appearance transitions for '

前端 未结 10 1605
一生所求
一生所求 2021-02-01 20:10

When I navigate through UIPageViewController faster than its transition animation I am getting \'Unbalanced calls to begin/end appearance transitions for <

10条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-01 21:11

    The above answers were right, but I think more elaborate than needed, and cookbook is helpful. So here is what seems to be working for me:

    In the view controller that sets up and calls the pageViewController, declare:

    @property (assign)              BOOL pageIsAnimating;
    

    and in viewDidLoad:

        pageIsAnimating = NO;
    

    add this:

    - (void)pageViewController:(UIPageViewController *)pageViewController willTransitionToViewControllers:(NSArray *)pendingViewControllers {
        pageIsAnimating = YES;
    }
    

    and add a couple of lines to:

    - (void)pageViewController:(UIPageViewController *)pageViewController
        didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers
       transitionCompleted:(BOOL)completed {
        if (completed || finished)   // Turn is either finished or aborted
            pageIsAnimating = NO;
        ...
    }
    

    The gestures are suppressed by declining to provide view controller information:

    - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
       viewControllerAfterViewController:(UIViewController *)viewController {
        if (pageIsAnimating)
            return nil;
        ...
        return after;
    }
    
    - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
      viewControllerBeforeViewController:(UIViewController *)viewController {
        if (pageIsAnimating)
            return nil;
        ...
        return before;
    }
    

    Oh, and orientation changes reset the flag:

    - (UIPageViewControllerSpineLocation)pageViewController:(UIPageViewController *)pageViewController
                   spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation {
        pageIsAnimating = NO;
        ...
    }
    

提交回复
热议问题