How can i know if UIPageViewController flipped forward or reversed?

shannoga picture shannoga · Jan 6, 2012 · Viewed 22.2k times · Source

I have a UIPageViewController and I just can not figure out how to know to what direction the user turned the page so i can set the page count appropriately.

Thanks Shani

Answer

roff picture roff · Feb 5, 2012

As Hejazi said

After a gesture-driven transition completes this delegate method is called:

pageViewController:didFinishAnimating:previousViewControllers:transitionCompleted:

The part that should be clarified is that completed will be YES if the page was fully turned and will be NO if the page did not actually turn. The NO case happens, for example, when the user just pulls up the corner of the page and then puts it back down without flipping the page.

This is the concept you will want to implement:

- (void)pageViewController:(UIPageViewController *)pvc didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed
{
    // If the page did not turn
    if (!completed)
    {
        // You do nothing because whatever page you thought 
        // the book was on before the gesture started is still the correct page
        return;
    }

    // This is where you would know the page number changed and handle it appropriately
    // [self sendPageChangeNotification:YES];
}