Finally found a solution to my problem which has caused me grief so hopefully this can help someone else.
The issue is if you set the pageViewControllers delegate to your viewController
for (UIGestureRecognizer *gR in self.pageController.view.gestureRecognizers)
{
if ([gR isKindOfClass:[UITapGestureRecognizer class]])
{
gR.enabled = NO;
}
else if ([gR isKindOfClass:[UIPanGestureRecognizer class]])
{
gR.delegate = self;
}
}
then returning nil from
pageViewController:viewControllerAfterViewController:
will crash!! only in iOS6!!
My issue was that I needed to set the delegate of the gestureRecognisers because I needed to intercept the panGesture in some situations, i.e not allowing the user to turn a page wilst touching certain parts of it due to some buttons there.
The solution is to put the logic from
pageViewController:viewControllerAfterViewController:
into
gestureRecognizer:shouldReceiveTouch:
because as long as we return NO from that then it wont go on to call
pageViewController:viewControllerAfterViewController:
and so no need to return nil and get a crash.
However, this didn't work on the first and last page in the sequence. For example on the first page, you want to allow the page to turn forward but not back. So I thought about looking at the GestureRecogniser passed in, casting it to a PanGesture, and then checking the velocity on this, if the velocity signifies turning back ( > 0.0f ) then just return NO. This sounded good but the velocity was always zero.
I then found a very helpful little function on the GestureRecognizer delegate called:
gestureRecognizerShouldBegin:gestureRecognizer
this function is called after
gestureRecognizer:shouldReceiveTouch:
but this time the velocity from the gesture is as I expected, so I can check the velocity and only return YES for the first page if it is > 0.0f