Progress of UIPageViewController

后端 未结 7 1118
礼貌的吻别
礼貌的吻别 2020-12-30 05:51

I would like to receive updates from the uipageviewcontroller during the page scrolling process. I want to know the transitionProgress in %. (This value should update when t

7条回答
  •  情歌与酒
    2020-12-30 06:02

    Based on Appgix solution, I'm adding this directly on my 'UIPageViewController' subclass. (Since I only need it on this one)

    For Swift 3:

    class MYPageViewControllerSubclass: UIPageViewController, UIScrollViewDelegate {
    
       override func viewDidLoad() {
              super.viewDidLoad()
    
              for subView in view.subviews {
                 if subView is UIScrollView {
                    (subView as! UIScrollView).delegate = self                
                 }
              }
        }
    
        // MARK: - Scroll View Delegate
    
        public func scrollViewDidScroll(_ scrollView: UIScrollView) {
            let point = scrollView.contentOffset
            var percentComplete: CGFloat
            percentComplete = fabs(point.x - view.frame.size.width)/view.frame.size.width
            NSLog("percentComplete: %f", percentComplete)
        }
    
        // OTHER CODE GOES HERE...
    
    }
    

提交回复
热议问题