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

前端 未结 10 1495
一生所求
一生所求 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

    Here's the Swift version of Bill Cheswick's answer (currently the top answer):

    Add a variable to hold the current state:

    var pageIsAnimating = false
    

    Set the animating state:

    func pageViewController(pageViewController: UIPageViewController, willTransitionToViewControllers pendingViewControllers: [UIViewController]) {
        self.pageIsAnimating = true
    }
    
    func pageViewController(pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
        if finished || completed {
            self.pageIsAnimating = false
        }
    }
    

    Block the transitions if it's currently animating:

    func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {
        if self.pageIsAnimating {
            return nil
        }
    
        // Your code here
    }
    
    func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {
        if self.pageIsAnimating {
            return nil
        }
    
        // Your code here
    }
    

    Thank you Bill Cheswick!

提交回复
热议问题