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?
Make use of your UIPageViewControllerDelegate methods and set up guards to prevent creating new page views when excessive page turns are detected.
I will try to ignore gesture on UIPageViewControllers while transitioning.
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:
and in viewDidLoad:
add this:
and add a couple of lines to:
The gestures are suppressed by declining to provide view controller information:
Oh, and orientation changes reset the flag:
Good answer from Basem Saadawy but it has some defect.
Actually the delegate's gestureRecognizerShouldBegin: could be called with no further animation started. This is possible if you start your gesture by vertical finger's moving and its horizontal offset is not enough to start the animation (but is enough to launch gestureRecognizerShouldBegin:). Thus our variable pageAnimationFinished will be set to NO without an actual animation. Therefore the pageViewController: didFinishAnimating: will never be called and you get the current page frozen without a possibility to change it.
That's why a better place to assign NO to this variable is a gesture recognizer's action method with examination of its velocity and translation (we are interested in horizontal direction only).
So the final steps are:
1) Declare an instance variable (a flag):
2) Set its initial value
3) Assign a delegate and a custom action to the pan gesture recognizers
3') Animation is really started when the gesture's translation is greater in horizontal direction and the finger is moving horizontally at a moment.
I guess the same logic is used in the internal recognizer's action assigned by UIPageViewController.
4) Disallowing a gesture if an animation is not finished.
5) Animation is finished
I played too much with it and seems this is a nice solution that works well.