以编程方式转动页面,指标不会改变

问题描述 投票:1回答:2

我尝试以下方法找到here

extension UIPageViewController {

func goToNextPage(){

    guard let currentViewController = self.viewControllers?.first else { return }

    guard let nextViewController = dataSource?.pageViewController( self, viewControllerAfter: currentViewController ) else { return }

    setViewControllers([nextViewController], direction: .forward, animated: true, completion: nil)

   }
}

它有效,但有一个问题:

以编程方式打开页面时,指示器不会移动。它们似乎只有在用户转动时才会移动。刷卡页面

这是在执行程序化转换后指标的样子:

enter image description here

相反,他们保持不变

enter image description here

这导致指标所显示的层次结构相当于[2,0,1]而不是[0,1,2]

这是我实施指标的方式:

func presentationCount(for PageViewController:UIPageViewController) -> Int {


    return 3

}

func presentationIndex(for PageViewController:UIPageViewController) -> Int {

    return 0
}

当以编程方式转动页面时,如何使点指示器移动?

ios swift swift3 uipageviewcontroller
2个回答
1
投票

遗憾的是,您无法更新UIPageViewController中嵌入的UIPageControl。但是,您可以在UIPageViewController中拥有自己的UIPageControl以获得完全控制。然后,您可以在更新页面时以编程方式更新UIPageControl属性。看看这个article.


0
投票

有一个解决方法获取UIPageViewController的子视图,将值设置为currentPage。

for subView in self.view.subviews{
     if let pageControl = subView as? UIPageControl,
         pageControl.numberOfPages >  currentIndex{
         pageControl.currentPage = currentIndex
     }
}
© www.soinside.com 2019 - 2024. All rights reserved.