UIPageViewController: Fade In/Out Animation Between Viewcontrollers?

blee908 picture blee908 · Sep 14, 2014 · Viewed 7.1k times · Source

I followed the tutorial over @ http://www.appcoda.com/uipageviewcontroller-storyboard-tutorial/ to implement a UIPageViewController. I need to make the transition between view controllers to fade in/out when the user scrolls between them.

An example of an app that does this is over here https://itunes.apple.com/us/app/tapiture/id645402534?mt=8

Answer

matt picture matt · Sep 14, 2014

Use the delegate pageViewController:willTransitionToViewControllers:. This is called as the gesture begins. You know what the old view controller is because it's already there. You know what the new view controller is because this message tells you. Thus you have access to their views. Thus you can change the alpha of their views.

The gesture may be cancelled, but then pageViewController:didFinishAnimating:previousViewControllers:transitionCompleted: tells you this, so you can fix the alpha of the existing view back again.

If you don't like that approach, you're going to have to subclass UIPageViewController, or write your own parent view controller that does the same sort of thing. The advantage there is that you have direct access to the scroll view and can track the scroll yourself. Writing an "infinite scroll view" is discussed in a WWDC video from some years ago; I've written one, but I abandoned it when UIPageViewController took on the scrolling style.