Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i know if UIPageViewController flipped forward or reversed?

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

like image 833
shannoga Avatar asked Jan 05 '12 23:01

shannoga


2 Answers

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];
}
like image 119
roff Avatar answered Nov 20 '22 20:11

roff


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

pageViewController:didFinishAnimating:previousViewControllers:transitionCompleted:

So by comparing the previousViewControllers parameter and pageViewController.viewControllers you can know the direction.

like image 7
Hejazi Avatar answered Nov 20 '22 22:11

Hejazi