Tell When a UIPageViewController is Scrolling (for Parallax Scrolling of an Image)

后端 未结 8 1948
灰色年华
灰色年华 2020-12-13 04:43

I am trying to make an effect similar to that found in the new Yahoo weather app. Basically, each page in the UIPageViewController has a background image, and w

8条回答
  •  长情又很酷
    2020-12-13 04:50

    Use @Paul's snippet -

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

    to implement this protocol : -(void)scrollViewDidScroll:(UIScrollView *)scrollView

    -(void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
    CGPoint point = scrollView.contentOffset;
    
    float percentComplete;
    percentComplete = fabs(point.x - self.view.frame.size.width)/self.view.frame.size.width;
    NSLog(@"percentComplete: %f", percentComplete);
    }
    

    This gives you the percentage completion of the scroll. Happy coding!

提交回复
热议问题