2
votes

I'm using a UIPageViewController to swipe through a series of viewcontrollers. I'd like the background of the parent viewcontroller to smoothly transition between colors when swiping, based on the position of the scroll between views. I was hoping UIPageViewController would have a delegate method similar to scrollViewDidScroll with the position, but it doesn't seem to.

Is there an alternate method or similar method to expose the position of the swipe as it occurs/changes?

EDIT: Since scrollview seems not to be exposed, I've come up with a perm/temp solution. When transitioning between pages I transition the parent background color over an Animation of 1 second. This does not directly tie to the swipe, or allow for half swipes, etc. But for regular side to side swipes it accomplishes the desired smooth effect instead of instant color change.

// code that occurs when a pageControl swipe occurs. 

UIColor *destinationColor = [UIColor redColor];  // the desired end color

[UIView animateWithDuration:1.0
                      delay:0
                    options:UIViewAnimationOptionAllowUserInteraction
                 animations:^{
                     self.pageViewController.view.backgroundColor = destinationColor;
                 }
                 completion:nil
];
2
What's your minimum deployment target? iOS 7 and greater?Acey
ios7 minimum. we don't support ios6.Miro
Unfortunately, you don't have access to the scroll view that's added to the page view controller's subviews when you use the scroll transition (Apple hasn't made that public). You'll have to create your own version of a page view controller, if you want that function.rdelmar

2 Answers

2
votes

While the UIScrollView of the UIPageViewController isn't exposed by default, it's actually not that hard to find, so you can do what you want by making your view controller an UIScrollViewDelegate and then doing something like this in the viewDidLoad method or the like:

for (UIView *view in pageViewController.view.subviews) {
    if ([view isKindOfClass:[UIScrollView class]]) {
        ((UIScrollView *)view).delegate = self;
        break;
    }
}

Now your view controller can implement scrollViewDidScroll: and be able to track the transition of the page view controller.

-1
votes

If you mean you want the transition between the two view controllers to track the user's finger as they swipe, then set the datasource and implement the methods: viewControllerBeforeController and viewControllerAfterController. If these are implemented, UIPageViewController will automatically implement a gesture recogniser which tracks the user's swipe and animates the transition between the two viewControllers accordingly.