Code Monkey home page Code Monkey logo

xlpageviewcontroller's Introduction

title

特点:

  • 采用UICollectionView+UIPageViewController方案,高性能,低功耗。
  • 支持刷新,内置缓存(非复用)机制,节省内存。
  • 默认配置样式丰富,可实现大部分主流App样式。
  • 支持用户自定义标题样式。

结构:

结构图

App举例:

App 示例
今日头条 image
腾讯新闻 image
澎湃新闻 image
爱奇艺 image
优酷 image
腾讯视频 image
网易新闻 image
人民日报 image

基本属性:

功能 示例
基本样式-标题正常显示 image
基本样式-标题显示在导航栏上 image
Segmented样式-标题正常显示 image
Segmented样式-标题显示在导航栏上 image
标题栏-局左 image
标题栏-局中 image
标题栏-局右 image
标题-自定义宽度 image
标题-自定义高度 image
标题-文字局上 image
标题-文字居下 image
标题-关闭标题颜色过渡 image
阴影动画-缩放 image
阴影动画-无 image
阴影末端形状-圆角 image
阴影末端形状-直角 image
阴影-居上 image
阴影-居中 image

特殊用法:

场景 示例
自定义Cell image
频道定制 image
多级嵌套 image
子View滚动冲突 image
手动切换 image

使用:

1、创建方法

1.1 导入头文件

#import "XLPageViewController.h"

1.2 遵守协议

@interface ViewController ()<XLPageViewControllerDelegate,XLPageViewControllerDataSrouce>

1.3 创建外观配置类。

注:config负责所有的外观配置,defaultConfig方法设定了默认参数,使用时可按需配置。 Config属性列表

  XLPageViewControllerConfig *config = [XLPageViewControllerConfig defaultConfig];

1.4 创建分页控制器

注:需要把pageViewController添加为当前视图控制器的子试图控制器,才能实现pageViewController子试图控制器中的界面跳转。

  XLPageViewController *pageViewController = [[XLPageViewController alloc] initWithConfig:config];
  pageViewController.view.frame = self.view.bounds;
  pageViewController.delegate = self;
  pageViewController.dataSource = self;
  [self.view addSubview:pageViewController.view];
  [self addChildViewController:pageViewController];

2、协议

2.1 XLPageViewControllerDelegate

//位置回调方法:回调切换位置
- (void)pageViewController:(XLPageViewController *)pageViewController didSelectedAtIndex:(NSInteger)index;

2.2 XLPageViewControllerDataSrouce

//根据index创建对应的视图控制器,每个试图控制器只会被创建一次。
- (UIViewController *)pageViewController:(XLPageViewController *)pageViewController viewControllerForIndex:(NSInteger)index;
//根据index返回对应的标题
- (NSString *)pageViewController:(XLPageViewController *)pageViewController titleForIndex:(NSInteger)index;
//返回分页数
- (NSInteger)pageViewControllerNumberOfPage;
//标题cell复用方法,自定义标题cell时用到
- (__kindof XLPageTitleCell *)pageViewController:(XLPageViewController *)pageViewController titleViewCellForItemAtIndex:(NSInteger)index;

3、自定义标题cell

3.1 创建一个XLPageTitleCell的子类

#import "XLPageTitleCell.h"

@interface CustomPageTitleCell : XLPageTitleCell

@end

3.2 注册cell、添加创建cell的数据源方法

[self.pageViewController registerClass:CustomPageTitleCell.class forTitleViewCellWithReuseIdentifier:@"CustomPageTitleCell"];
- (XLPageTitleCell *)pageViewController:(XLPageViewController *)pageViewController titleViewCellForItemAtIndex:(NSInteger)index {
    CustomPageTitleCell *cell = [pageViewController dequeueReusableTitleViewCellWithIdentifier:@"CustomPageTitleCell" forIndex:index];
    return cell;
}

3.3 复写cell父类方法

//通过此父类方法配置cell是否被选中样式
- (void)configCellOfSelected:(BOOL)selected {

}

//通过此父类方法配置cell动画 type:区分是当前选中cell/将要被选中的cell progress,动画进度0~1
- (void)showAnimationOfProgress:(CGFloat)progress type:(XLPageTitleCellAnimationType)type {
    
}

4、特殊情况处理

4.1 和子view冲突问题

pageViewController的子视图中存可滚动的子view,例如UISlider、UIScrollView等,如果子view和pageViewController发生滚动冲突时,可设置子view的xl_letMeScrollFirst属性为true。

  slider.xl_letMeScrollFirst = true;

其他

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.