Get scroll position of UIPageViewController

后端 未结 6 952
轻奢々
轻奢々 2020-12-14 18:23

I am using a UIPageViewController, and I need to get the scroll position of the ViewController as the users swipe so I can partially fade some assets while the

6条回答
  •  被撕碎了的回忆
    2020-12-14 18:47

    To make the code as readable and separated as possible, I would define an extension on UIPageViewController:

    extension UIPageViewController {
      var scrollView: UIScrollView? {
        view.subviews.first(where: { $0 is UIScrollView }) as? UIScrollView
      }
    }
    

    It's quite easy to set yourself as the delegate for scroll view events, as so:

    pageViewController.scrollView?.delegate = self
    

提交回复
热议问题