Latest 1.0.1
Homepage https://github.com/Byxc/DDKPageViewController
License MIT
Platforms ios 8.0, requires ARC
Frameworks UIKit
Authors

一个使用UIPageViewController封装实现的分页控件,在UIPageViewController的基础上做了一些改善以满足日常简单的分页需求

demo

导入

cocoapods方式

pod 'DDKPageViewController'

// 在使用的类中导入头文件
#import <DDKPageViewController.h>

手动导入

请将相关文件下载并导入到项目中

// 在使用的类中导入头文件
#import "DDKPageViewController.h"

使用方法

使用方法基本和UIPageViewController一致,但需要使用pageSource中的代理方法来代替UIPageViewController中原有的pageViewController: viewControllerBeforeViewController:pageViewController: viewControllerAfterViewController :方法,使用方法如下:

  1. 初始化
// 使用UIPageViewController相同的创建方法
DDKPageViewController *pageViewController = [[DDKPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
// 设置控件大小
pageViewController.view.frame = pageViewFrame;
// 设置数据代理(替代dataSource中的部分方法)
pageViewController.pageSource = self;
[self.view addSubView:pageViewController.view];
[pageViewController didMoveToParentViewController:self];
  1. 代理方法
#pragma mark - DDKPageViewControllerPageSource
// 必选方法,需要在此方法中返回指定索引值的UIViewController,返回nil代表当前页索引无效
- (UIViewController *)pageView:(DDKPageViewController *)pageView loadIndex:(NSInteger)index {
    UIViewController *viewController = nil;
    if (0 == index%2) {
        FirstViewController *first = [FirstViewController new];
        first.index = index;
        viewController = first;
    }
    else {
        SecondViewController *second = [SecondViewController new];
        second.index = index;
        viewController = second;
    }
    return viewController;
}
// 可选方法,用于通知页索引值的更新
- (void)pageView:(DDKPageViewController *)pageView indexUpdate:(NSInteger)index {
    self.title = [NSString stringWithFormat:@"%zd",index];
}
  1. 翻页

使用属性currentPageIndex或者setCurrentPageIndex方法设置当前需要呈现的UIViewController的页索引值,DDKPageViewController将会通过调用代理方法pageView: loadIndex:获取并设置给定索引值的UIViewController

#pragma mark - Action
- (IBAction)lastButtonClickAction:(id)sender {
    _pageViewController.currentPageIndex -= 1;
}

- (IBAction)nexButtonClickAction:(id)sender {
    _pageViewController.currentPageIndex += 1;
}

说明

该控件是本人在项目中使用UIPageViewController时对UIPageViewController的封装和处理,可以满足常见的分页功能,使用过程中如遇问题,欢迎和我联系,如果有好的建议,欢迎告知😊。

Latest podspec

{
    "name": "DDKPageViewController",
    "version": "1.0.1",
    "summary": "u57fau4e8eUIPageViewControlleru5c01u88c5u7684u5206u9875u63a7u5236u5668u63a7u4ef6",
    "description": "u4e00u4e2au4f7fu7528UIPageViewControlleru5c01u88c5u5b9eu73b0u7684u5206u9875u63a7u4ef6uff0cu5728UIPageViewControlleru7684u57fau7840u4e0au505au4e86u4e00u4e9bu6539u5584u4ee5u6ee1u8db3u7b80u5355u7684u5206u9875u529fu80fd",
    "homepage": "https://github.com/Byxc/DDKPageViewController",
    "license": "MIT",
    "authors": {
        "u767du4e91u5fc3u57ce": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/Byxc/DDKPageViewController",
        "tag": "1.0.1"
    },
    "source_files": "DDKPageViewController/*.{h,m}",
    "frameworks": "UIKit",
    "requires_arc": true
}

Pin It on Pinterest

Share This