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

后端 未结 8 1953
灰色年华
灰色年华 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: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)
    

提交回复
热议问题