Observe the transition state of UIPageViewController

450 views Asked by At

I would like to tweak the visual state of a view based on how much it is "on screen". These views are managed by a UIPageViewController, using the stock .Scroll transition style.

The behavior I would like is to have the title be 100% opacity when it is 100% on screen and 0% opacity when it is 0% on screen, transitioning between the two as a function of the panning navigation gesture/animation.

I am hoping I can plug into the x-coordinate or a percentage animation complete, but I don't see a property anywhere. I understand the page view controller is using a scroll view behind the scenes but am a little concerned about reaching into a private API, and I don't see a public method to access it.

Is there any way to hook into the existing interactive transition so that I can add some additional behaviors to the child view controllers that scale based on the completion percentage?

Update:

  • Tried implementing UIScrollViewDelegate's scrollViewDidScroll. No luck. I think page view controller does to call methods on this delegate.
  • Tried using viewWillDisappear/viewDidAppear in the child view controllers. This is functional but the animation is not responsive since these are called as single events at the start/end of user behaviors.
1

There are 1 answers

0
MGY On

You already update your question about UIScrollViewDelegate but, for simillary problem I use UIScrollViewDelegate like this:

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

in my case UIPageViewController is inside a container view controller. That's why I added a delegate (PagerDelegate) in my class to call ContainerViewController when scroll view did scrolls:

#pragma mark - UIScrollViewDelegate

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    [self.pagerDelegate viewDidScroll:scrollView];
}

at ContainerViewController:

#pragma mark - PagerDelegate

- (void)viewDidScroll:(UIScrollView*)scrollView {
    // calculate the transition percentage and do anything you need...
}

Hope I understand correctly and it helps someone else. (probably you fixed this problem already because asked Jun 16 '15)