Hide dots on final page of UIPageViewController swift

后端 未结 5 1545
小鲜肉
小鲜肉 2021-01-16 08:59

I have four pages in a UIPageViewController, and I\'d like to hide the dots on the last page. I successfully made a function that gets called on the last page of the UIPageV

5条回答
  •  囚心锁ツ
    2021-01-16 09:37

    I found that you can't actually hide the page control as it just never works. But a bit of a hack is to add this to your code:

        func pageViewController(pageViewController: UIPageViewController, willTransitionToViewControllers pendingViewControllers: [UIViewController]) {
            if let lastVC = pendingViewControllers.last?.isKindOfClass(youLastViewController){
                if lastVC == true {
                    for view in self.view.subviews {
                        if view is UIScrollView {
                            view.frame = UIScreen.mainScreen().bounds
                        } else if view is UIPageControl {
                            view.center.y = self.view.frame.height * 1.5
                        }
                    }
                }else {
                    for view in self.view.subviews {
                        if view is UIScrollView {
                            view.frame = UIScreen.mainScreen().bounds
                        } else if view is UIPageControl {
                            view.center.y = self.view.frame.height * 0.92
                        }
                    }
                }
            }
        }
    }
    

    This actually move the page control of the screen and the same as hiding it.

提交回复
热议问题