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

后端 未结 8 1918
灰色年华
灰色年华 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 05:09
    for (UIView *view in self.pageViewController.view.subviews) {
        if ([view isKindOfClass:[UIScrollView class]]) {
             [(UIScrollView *)view setDelegate:self];
        }
    } 
    

    this gives you access to all standard scroll view API methods. And this is not using private Apple API's.

    I added traversing through subviews, to 100% find the UIPageViewController's inner scroll view WARNING: Be careful with scrollview.contentOffset. It resets as the controller scrolls to new pages

    If you need persision scrollview offset tracking and stuff like that, it would be better to use a UICollectionViewController with cells sized as the collection view itself and paging enabled.

    0 讨论(0)
  • 2020-12-13 05:12

    I would do this:

    Objective-C

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

    and implement this protocol

    - (void)scrollViewDidScroll:(UIScrollView *)scrollView
    

    Swift

    for view in self.pageViewController.view.subviews {
      if let scrollView = view as? UIScrollView {
        scrollView.delegate = self
      }
    }
    

    and implement this protocol

    func scrollViewDidScroll(scrollView: UIScrollView)
    
    0 讨论(0)
提交回复
热议问题