转换页面与uipageviewcontroller

时间:2016-10-01 15:58:38

标签: ios swift storyboard swift3

我有一个包含UIPageViewController的视图容器。对他来说,他们与UIImageView的2个viewController相关联。几乎所有东西都适用。我无法更改动画以滚动图像。动画总是页面卷曲,而我想要一个简单的滚动。怎么办?

class MyPageViewController: UIPageViewController, UIPageViewControllerDataSource, UIPageViewControllerDelegate {

var pages = [UIViewController]()

override func viewDidLoad() {
    super.viewDidLoad()

    self.delegate = self
    self.dataSource = self

    let page1: UIViewController! = storyboard?.instantiateViewController(withIdentifier: "page1")
    let page2: UIViewController! = storyboard?.instantiateViewController(withIdentifier: "page2")

    pages.append(page1)
    pages.append(page2)

    setViewControllers([page1], direction: UIPageViewControllerNavigationDirection.forward, animated: false, completion: nil)

}

func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
    let currentIndex = pages.index(of: viewController)!
    let previousIndex = abs((currentIndex - 1) % pages.count)
    return pages[previousIndex]

}

func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
    let currentIndex = pages.index(of: viewController)!
    let nextIndex = abs((currentIndex + 1) % pages.count)
    return pages[nextIndex]
}

private func presentationCountForPageViewController(pageViewController: UIPageViewController) -> Int {
    return pages.count
}

private func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int {
    return 0
}

}

Storyboard

1 个答案:

答案 0 :(得分:1)

您是如何发起UIPageViewController的?

从代码中,您可以在构造函数中指定transitionStyle,如here

所示

从情节提要中,您可以在故事板中指定相同的transitionStyle,如此SO answer

所示