DLAutoSlidePageViewController 4.0.0

DLAutoSlidePageViewController 4.0.0

测试已测试
Lang语言 SwiftSwift
许可证 MIT
释放上次发布2024年2月
SPM支持 SPM

Alonso 维护。



  • Alonso Alvarez

DLAutoSlidePageViewController

Version License Platform Swift 5

演示

示例

要运行示例项目,首先克隆仓库,然后从 Example 目录运行 pod install

需求

DLAutoSlidePageViewController 需要iOS 13.0 和 Swift 5.0 或更高版本。

安装

CocoaPods

PageViewController 可以通过 CocoaPods 获取。要安装它,只需将以下行添加到您的 Podfile 中

pod "DLAutoSlidePageViewController"

Swift Package Manager

要使用 Swift Package Manager 集成,请将以下内容作为依赖添加到您的 Package.swift

.package(url: "https://github.com/DeluxeAlonso/DLAutoSlidePageViewController.git", .upToNextMajor(from: "3.0.0"))

使用说明

创建一个 DLAutoSlidePageViewController 实例,并向它提供一个 UIViewController 数组。

let firstVC = storyboard?.instantiateViewController(withIdentifier: 'FirstVC')
let secondVC = storyboard?.instantiateViewController(withIdentifier: 'SecondVC')
let pages = [firstVC, secondVC]

let pageViewController = DLAutoSlidePageViewController(pages: pages)
                                                       
addChildViewController(pageViewController)
containerView.addSubview(pageViewController.view)
pageViewController.view.frame = containerView.bounds

外观和展示配置

有两种方式来配置 DLAutoSlidePageViewController 的外观和展示。

  1. 在实例化之前,您可以通过 DefaultAutoSlideConfiguration 类进行全局配置。
let pages = [firstVC, secondVC]

DefaultAutoSlideConfiguration.shared.timeInterval = 5.0
DefaultAutoSlideConfiguration.shared.interPageSpacing = 3.0
DefaultAutoSlideConfiguration.shared.hidePageControl = false
let pageViewController = DLAutoSlidePageViewController(pages: pages)
  1. 您可以创建一个符合 AutoSlideConfiguration 协议的自定义配置实例,并将其传递给 DLAutoSlidePageViewController 的初始化器。
struct CustomConfiguration: AutoSlideConfiguration {
    var timeInterval: TimeInterval = 10.0
    var navigationOrientation: UIPageViewController.NavigationOrientation = .vertical
}
let pages = [firstVC, secondVC]
let pageViewController = DLAutoSlidePageViewController(pages: pages, configuration: CustomConfiguration())

可用的配置属性

DLAutoSlidePageViewController 可以通过以下属性进行自定义。

属性 类型 描述
timeInterval TimeInterval 每个页面自动过渡使用的时间间隔。
transitionStyle UIPageViewController.TransitionStyle 页面翻转过渡的样式。
navigationOrientation UIPageViewController.NavigationOrientation 页面翻转过渡的方向。
navigationDirection UIPageViewController.NavigationDirection 页面翻转的浏览方向。
interPageSpacing Float 页面之间的空间。
spineLocation UIPageViewController.SpineLocation 书脊的位置。仅当过渡样式为 UIPageViewController.TransitionStyle.pageCurl 时有效。
hidePageControl Bool 决定是否显示页码控制器。
currentPageIndicatorTintColor UIColor 用于当前页指示器的着色色。
pageIndicatorTintColor UIColor 用于页指示器的着色色。
pageControlBackgroundColor UIColor 用于页码控制器的背景色。
shouldAnimateTransition Bool 指示是否要动画自动过渡。
pageControlDirection UIPageControl.Direction 描述页码控制器指示器布局的方向。从 iOS 16 开始可用。
pageControlPreferredIndicatorImage UIImage 用于指示器的首选图片。建议使用符号图片。默认为 nil。从 iOS 14 开始可用。
pageControlPreferredCurrentPageIndicatorImage UIImage 用于当前页指示器的首选图片。从 iOS 16 开始可用。
shouldSlideOnTap Bool 指示当用户轻按左右侧时,页面控制器是否应该滑动后退/前进。
tappableAreaPercentage Float 检测左右两侧触摸操作的可触摸区域百分比。默认值为20%。仅在shouldSlideOnTap设置为true时使用。
覆盖手势行为 Bool 默认为False。如果设置为true,则在需要时将调用DLAutoSlidePageViewControllerGestureDelegate方法,并忽略shouldSlideOnTap属性。

作者

Alonso Alvarez, [email protected]

许可证

DLAutoSlidePageViewController在MIT许可证下可用。有关更多信息,请参阅LICENSE文件。