使用 transitionStyle .scroll 时如何将 UIPageViewControllerSpineLocation 设置为 .mid

How to set UIPageViewControllerSpineLocation to .mid when in using transitionStyle .scroll

我正在创建一个 iPhone 抽认卡应用程序,该应用程序将用于学习各种术语。目前,我正在使用 UIPageViewController 来显示每个连续的卡片(视图控制器)。当用户点击一张卡片时,它会翻转并显示背面,当他们向左或向右滑动时,他们可以在卡片之间滚动。 Current App interface

到目前为止效果很好,但我希望能够在横向显示卡片的正面和背面。通常这很容易通过使用 UIPageViewControllerDelegate 的方法 func pageViewController(_ pageViewController: UIPageViewController, spineLocationFor orientation: UIInterfaceOrientation) 并返回 .mid 如果方向是水平的。但是,由于我没有使用 .pageCurl 而是 .scroll 作为我的 pageViewController 的 transitionStyle,因此永远不会调用此方法。 Apple Documentation 不使用时也无法手动设置 .pageCurl。 Apple 的文档说:

A spine location is only valid if the transition style is pageCurl. If the transition style is pageCurl, the default value for this property is min; otherwise, the default is none.

我尝试添加一个在横向时调用的方法:

func showBothSides(){
    let currentViewController = self.pageViewController!.viewControllers![0] as! PracticePageDataVC
    let viewControllers: [UIViewController] = [currentViewController, currentViewController]
    self.pageViewController!.setViewControllers(viewControllers, direction: .forward, animated: true, completion: {done in })
}

但是这个returns错误:“'提供的视图控制器的数量 (2) 与请求的转换所需的数量 (1) 不匹配'”

所以基本上我正在寻找一种替代解决方案来并排显示两个视图控制器,同时仍然保持卡片之间水平滚动过渡的功能。

So basically I am looking for an alternative solution to show two view controllers side by side while still maintained the functionality of scrolling horizontally between cards

你有两个选择。

  • UIPageViewController 中的 "page" 本身可以是自定义父(容器)视图控制器,其两个子视图并排显示。

  • 您可以完全放弃使用 UIPageViewController,并使用水平分页滚动视图实现您自己的界面(毕竟在页面视图控制器存在之前我们就是这样做的)。