KRNPageViewController 0.0.3

KRNPageViewController 0.0.3

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最后发布2017年4月

Julian Drapaylo 维护。



  • 作者:
  • Julian Drapaylo

KRNPageViewController 是一个封装在 UIPageViewController 之上的工具,简化了其使用。

关于

许多应用程序都有所谓的欢迎屏幕。欢迎屏幕是在首次启动应用程序或在使用户授权/注册之前显示的滑动界面。实现欢迎屏幕最流行的解决方案是使用 UIPageViewController。从头开始与 UIPageViewController 一起工作需要执行一些典型的重复性操作,如实现 UIPageViewControllerDelegate 和 UIPageViewControllerDataSource 的方法。

KRNPageViewController 的编写是为了简化在 iOS 中创建和设置欢迎屏幕,隐藏底层的工作原理。

安装

####CocoaPods

只需将 pod 'KRNPageViewController' 添加到您的 Podfile,并在项目文件夹中的终端中运行 pod install

在您需要使用 KRNPageViewController 的文件中写入 #import "KRNPageViewController.h"

使用方法

1.创建 KRNPageViewController 的属性 并使用以下方法分配其实例

KRNPageViewController *pageViewController = 
[KRNPageViewController createdAsEmbeddedToView:self.embeddedView 
ofViewController:self];

其中 embeddedView 是主视图中的 subview 层次中的视图,该视图将添加到 KRNPageViewController。

然后必须使用其属性来 配置 KRNPageViewController 的实例

pageViewController.pagesCount = 3; // number of pages
pageViewController.initialIndex = 0; //initial page index from which presentation of KRNPageViewController will start
pageViewController.embeddedPageControl = YES; // optional - use embedded page controller (NO - by default)

实现对 KRNPageViewControllerDelegate 协议 并将实现此协议的实例分配给 KRNPageViewController 的 controllerDelegate 属性。

pageViewController.controllerDelegate = self; //self must conform to KRNPageViewControllerDelegate protocol

KRNPageViewControllerDelegate 有两个方法

@required
- (UIViewController *)viewControllerAtIndex:(NSUInteger)index;  //implement this method to return appropriate view controller for index.
@optional
- (void)viewControllerWithIndexPresented:(NSInteger)index; //implement this method to handle event of presenting viewControllerWithIndex

viewControllerAtIndex: 是一个必需的方法,充当 KRNPageViewController 的数据源,并为 KRNPageViewController 的适当索引返回 UIViewController。索引范围取决于 KRNPageViewController 实例的 pagesCount 属性值,等于 0..<pagesCount。因此,如果您有三个用于欢迎屏幕的屏幕,则应将 pagesCount 属性设置为 3,以便适当的视图控制器索引范围为 0、1 和 2。

viewControllerWithIndexPresented: 在 KRNPageViewController 的下一个视图控制器呈现后调用。用于处理此事件和 UIPageControl 实例的设置,如果实现了该实例。

有关更多详细信息,请参阅 KRNPageViewControllerExample 项目。

要求

  • iOS 8.0 及以上
  • XCode 6+

许可

KRNPageViewController 采用 MIT 许可协议发布。有关详细信息,请参阅 LICENSE 文件。

联系

有任何建议或问题?请创建 Github issue 或与我联系。

LinkedIn