When I navigate through UIPageViewController
faster than its transition animation I am getting 'Unbalanced calls to begin/end appearance transitions for <MyDataViewController>
' and one of the two views in landscape isn't shown until I try to turn the page.
Anybody has an idea to solve this bug?
My solution in swift, simple and working:
Add below code
How about this:
Solved following these steps:
1- Declare a flag to indicate that the animation has finished or not:
2- Set this flag to true in viewDidLoad:
3- Disable tapGesture for the pageViewController and assign 'self' to panGestureRecognizer delegate:
4- Allow/Disallow panGestureRecognizer through the following gesture recognizer delegate method:
5- Add the following pageViewController delegate method:
Here's a QUICK version using the delegate:
add this code (make sure you're including the UIPageViewControllerDelegate in your header or class extension, and assign
self.pageViewController.delegate = self;
):then check
self.pageAnimationFinished
and return nil if it's ==NO
.Longer Explanation:
We can use this delegate method from
UIPageViewControllerDelegate
to know when the animation from flipping or swiping through pages finishes. Using this we just can implement it like this:then, just return
nil
in yourand
when
pageAnimationFinished == NO
. Be sure to setpageAnimationFinished
toNO
when you animate. The best way to know when you animate is by using the opposite ofnamely:
I haven't seen that warning ever since and this can be done in 1/3 of the lines as the other solutions. And it's MUCH easier to follow.
Here's the Swift version of Bill Cheswick's answer (currently the top answer):
Add a variable to hold the current state:
Set the animating state:
Block the transitions if it's currently animating:
Thank you Bill Cheswick!
I had to add it to viewDidAppear: to make it work