Get user swiping direction in UIPageViewController

后端 未结 5 2065
长发绾君心
长发绾君心 2020-12-06 11:20

These two methods viewControllerBeforeViewController and viewControllerAfterViewController of the UIPageViewControllerDataSource don\'

5条回答
  •  感动是毒
    2020-12-06 11:33

    Firstly in your viewControllerForIndex method assign viewcontroller.view.tag = index so that every viewcontroller.view has an assigned value

    Have a currentIndex property which is initially assigned to that index of the viewcontroller which you have instantiated inside pageviewcontroller

    Now in didFinishAnimating do the following

    func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
            if !completed {
                return     // return if animation is not completed
            }
           let pCont = bottomDataContainer?.viewControllers?[0] as? CustomVC   //take 
           out current VC
    
            if currentIndex < pCont?.view.tag ?? 0 {
                topNavView.goToNextDate()
            }else{
                topNavView.goToPrevDate()
            }
            selectedIndex = pCont?.view.tag ?? 0
        }
    

提交回复
热议问题