PageViewController current page index in Swift

前端 未结 12 2105
你的背包
你的背包 2021-02-01 15:37

I want to get current index of a pageViewController, I don\'t know how I get the visible pages index.

func pageViewController(pageViewController: UIPageViewContr         


        
12条回答
  •  情歌与酒
    2021-02-01 16:35

    Add this code to your UIPageViewController.

    var pages = [UIViewController]()
    var currentIndex: Int {
        guard let vc = viewControllers?.first else { return 0 }
        return pages.firstIndex(of: vc) ?? 0
    }
    

提交回复
热议问题