2
votes

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

4
Do you mean they should slide (scroll) and fade?matt
Yes! I'm hoping there's some sort of library out there for this.blee908

4 Answers

10
votes

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.

0
votes

Using the suggestion from @matt, heres how I ended up implementing it:

- (void)pageViewController:(UIPageViewController *)pageViewController willTransitionToViewControllers:(NSArray<UIViewController *>
*)pendingViewControllers {

    _nextVC = [pendingViewControllers objectAtIndex:0];

}

- (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(nonnull NSArray<UIViewController *> *)previousViewControllers transitionCompleted:(BOOL)completed {
    if (completed)
    {
        [_welcomeBackground setImage:[NSString stringWithFormat:@"welcome_intro_image_%d", _nextVC.view.tag]] 
    } 
}

We check for completed to make sure the user actually moved on to the next page, then set the correct image for that page according _nextVC's index which is stored in its tag property.

0
votes

Use the custom SCPageViewController and fade the view in the pageViewController:didNavigateToOffset: delegate method

-4
votes

This is included in the default transition styles in interface builder