我试图使用UIPageViewController
在控制器之间移动。一切都运行正常,但唯一的问题是我正在改变故事板中从页面卷曲到滚动的过渡样式。但它不起作用。当我运行应用程序并在控制器之间移动时,动画是页面卷曲!
我的代码很简单,你可以检查一下:
override func viewDidLoad() {
super.viewDidLoad()
let firstViewController = orderedViewControllers[1]
setViewControllers([firstViewController],
direction: .forward,
animated: false,
completion: nil)
self.delegate = self
self.dataSource = self
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
guard let viewControllerIndex = orderedViewControllers.index(of: viewController) else {
return nil
}
let previousIndex = viewControllerIndex - 1
// User is on the first view controller and swiped left to loop to
// the last view controller.
guard previousIndex >= 0 else {
return nil
}
guard orderedViewControllers.count > previousIndex else {
return nil
}
return orderedViewControllers[previousIndex]
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
guard let viewControllerIndex = orderedViewControllers.index(of: viewController) else {
return nil
}
let nextIndex = viewControllerIndex + 1
let orderedViewControllersCount = orderedViewControllers.count
// User is on the last view controller and swiped right to loop to
// the first view controller.
guard orderedViewControllersCount != nextIndex else {
return nil
}
guard orderedViewControllersCount > nextIndex else {
return nil
}
return orderedViewControllers[nextIndex]
}
```
您需要在实例化控制器时更改此transitionStyle
PageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal)