如何在UIPageViewController SWIFT的最后一个视图上隐藏点

时间:2016-08-17 15:27:16

标签: swift swift2 uipageviewcontroller uipagecontrol

我希望能够在UIPageViewController的最后一个视图中隐藏分页点。有question已经问过它,但它永远不会被回答。

如果有人能够概述一下这是如何实现的。

由于

编辑:

func pageViewController(pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
        pageControl.hidden = true
        print(pageControl.hidden)//Always is false
    }

1 个答案:

答案 0 :(得分:1)

使用UIPageViewControllerDelegate方法:

let pageControl = UIPageControl()

override func viewDidLoad(){
    super.viewDidLoad()
    pageControl.numberOfPages = numberOfPages()
    pageControl.currentPage = 0
    view.addSubview(pageControl)
    pageControl.currentPageIndicatorTintColor = UIColor.whiteColor()
    pageControl.pageIndicatorTintColor = UIColor.whiteColor().colorWithAlphaComponent(0.4)
}

func numberOfPages() -> Int {
    return 4 //your number of pages
}

func pageViewController(pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
    if (index == numberOfPages()-1){
          pageControl.hidden = true
    }else{
          pageControl.hidden = false
    }
}

你也可以迁移到icarousel它非常强大并且很容易实现https://www.youtube.com/watch?v=OLvZbXOAZQY