UIPageViewController 中的离屏页面限制

Offscreen Page Limit in UIPageViewController

我想在开头加载 UIPageViewController 内的所有页面。在 Android 中使用 setOffScreenPageLimit 查看寻呼机的方法很容易。有可能在 swift 中实现吗?

是也不是。您可以一次手动将一个或两个控制器传递给您的 UIPageViewController 或实现 UIPageViewControllerDataSource 以在需要时调用和获取控制器。

When defining a page view controller interface, you can provide the content view controllers one at a time (or two at a time, depending upon the spine position and double-sided state) or as-needed using a data source. When providing content view controllers one at a time, you use the setViewControllers(_:direction:animated:completion:) method to set the current content view controllers. To support gesture-based navigation, you must provide your view controllers using a data source object. The data source for a page view controller is responsible for providing the content view controllers on demand and must conform to the UIPageViewControllerDataSource protocol. The delegate object—an object that conforms to the UIPageViewControllerDelegate protocol—provides some appearance-related information and receives notifications about gesture-initiated transitions. This class is generally used as-is, but can also be subclassed.

https://developer.apple.com/documentation/uikit/uipageviewcontroller

您可以 return 委托方法中的 nil 来通知页面控制器关于最后一个视图控制器。

UIPageViewController 上没有 属性。但是,您可以为此目的使用 UIScrollView 并在安装时实例化所有视图。您也可以使用许多第三方框架。