Swift,如何在UIPageViewController中获取当前的显示控制器

时间:2017-06-20 02:45:09

标签: ios swift uipageviewcontroller

UIPageViewControllerDelegate

func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
    let viewer = pageViewController.childViewControllers[0] as! KKPhotoViewerController //So I got controller is a constant
    print(pageViewController.childViewControllers)
    print(previousViewControllers)
    photos.selectedIndex = viewer.photoIndex
    currentViewer = viewer
}

1 个答案:

答案 0 :(得分:0)

试试这个:

if self.pageViewController?.viewControllers?.count > 0 {
   let currentController = self.pageViewController?.viewControllers![0]
}