UIPageViewController - 不是从头开始,而是从中间开始(第 2 页)
UIPageViewController - start not at the beginning, but in the middle (page 2)
我设置了一个 PageViewController
三页。但是,我希望它从第 2 页(中间)开始。但是我不知道该怎么做。
我知道你这样设置开始 viewController
:
pageViewController.setViewControllers([viewControllerAtIndex(startIndex)!], direction: .forward, animated: true, completion: nil)
但是你只能说direction
forward
或者reverse
。但在这种情况下,两者都是。
我能做什么?谢谢!
您对 startViewController 的实现是正确的
pageViewController.setViewControllers([viewControllerAtIndex(startIndex)!], direction: .forward, animated: false, completion: nil)
在您的 UIPageViewControllerDataSource 实现中,也实现这个方法:
func presentationIndex(for pageViewController: UIPageViewController) -> Int {
return startIndex
}
您可能还需要
func presentationCount(for pageViewController: UIPageViewController) -> Int {
return pageData.count
}
我设置了一个 PageViewController
三页。但是,我希望它从第 2 页(中间)开始。但是我不知道该怎么做。
我知道你这样设置开始 viewController
:
pageViewController.setViewControllers([viewControllerAtIndex(startIndex)!], direction: .forward, animated: true, completion: nil)
但是你只能说direction
forward
或者reverse
。但在这种情况下,两者都是。
我能做什么?谢谢!
您对 startViewController 的实现是正确的
pageViewController.setViewControllers([viewControllerAtIndex(startIndex)!], direction: .forward, animated: false, completion: nil)
在您的 UIPageViewControllerDataSource 实现中,也实现这个方法:
func presentationIndex(for pageViewController: UIPageViewController) -> Int {
return startIndex
}
您可能还需要
func presentationCount(for pageViewController: UIPageViewController) -> Int {
return pageData.count
}