Giter VIP home page Giter VIP logo

cwcarousel's Introduction

CWCarousel

基于collectionView实现的通用无限轮播图封装.

  1. issues里面的可以重现的问题已经修复.
  2. 部分不能重现的问题暂未处理.
  3. 请大家提issue尽量描述详细些,最好能提供代码或者截图.请附上是OC版本还是Swift版本的问题.
  4. 谢谢配合,大家一起进步.

代码示例为oc代码, 项目中已有swift版本,请自行下载

oc版本支持cocoaPods安装 pod search OC_CWCarousel

OC版本记录

版本号 更新内容
1.1.0 修复了之前的一些bug
1.1.1 添加了无限轮播功能开关 endless
1.1.2 控件优化
1.1.3 提升了一个版本号
1.1.4 修复样式3在320尺寸屏幕上可能出现的问题
1.1.5 1.新增了2个代理回调
2.点击事件代理回调逻辑优化

swift版本记录

版本号 更新内容
1.1.0 功能同OC版 1.1.0
1.1.1 添加了无限轮播功能开关 endless
1.1.2 修复样式3在320尺寸屏幕上可能出现的问题
1.1.3 适配swift5.0
1.1.4 修复通过layout创建视图,偶现不自动轮播问题.

example.gif

  • 目前支持4种样式
typedef NS_ENUM(NSUInteger, CWCarouselStyle) {
CWCarouselStyle_Unknow = 0,     ///<未知样式
CWCarouselStyle_Normal,         ///<普通样式,一张图占用整个屏幕宽度
CWCarouselStyle_H_1,            ///<自定义样式一, 中间一张居中,前后2张图有部分内容在屏幕内可以预览到
CWCarouselStyle_H_2,            ///<自定义样式二, 中间一张居中,前后2张图有部分内容在屏幕内可以预览到,并且中间一张图正常大小,前后2张图会缩放
CWCarouselStyle_H_3,            ///<自定义样式三, 中间一张居中,前后2张图有部分内容在屏幕内可以预览到,中间一张有放大效果,前后2张正常大小
};

CWCarouselStyle_Normal

normal.gif

CWCarouselStyle_H_1

H_1.gif

CWCarouselStyle_H_2

H_2.gif

CWCarouselStyle_H_3

H_3.gif

  • 控件实例对象创建
  1. 创建flowLayout对象,设置轮播图风格
/**
构造方法

@param style 轮播图风格
@return 实例对象
*/
- (instancetype)initWithStyle:(CWCarouselStyle)style;

// egg:
CWFlowLayout *flowLayout = [[CWFlowLayout alloc] initWithStyle:[self styleFromTag:tag]];
  1. 创建容器对象
/**
创建实例构造方法

@param frame 尺寸大小
@param delegate 代理
@param datasource 数据源
@param flowLayout 自定义flowlayout
@return 实例对象
*/
- (instancetype _Nullable )initWithFrame:(CGRect)frame
                                delegate:(id<CWCarouselDelegate> _Nullable)delegate
                              datasource:(id<CWCarouselDatasource> _Nullable)datasource
                              flowLayout:(nonnull CWFlowLayout *)flowLayout;

// egg:
CWCarousel *carousel = [[CWCarousel alloc] initWithFrame:self.animationView.bounds
                                                delegate:self
                                              datasource:self
                                              flowLayout:flowLayout];
  1. 注册自定义cell,并实现代理方法,刷新视图
[carousel registerViewClass:[UICollectionViewCell class] identifier:@"cellId"];
[carousel freshCarousel];

#pragma mark - Delegate
// 每个轮播图cell样式
- (UICollectionViewCell *)viewForCarousel:(CWCarousel *)carousel indexPath:(NSIndexPath *)indexPath index:(NSInteger)index{
    UICollectionViewCell *cell = [carousel.carouselView dequeueReusableCellWithReuseIdentifier:@"cellId" forIndexPath:indexPath];
    /*
    your code
    */
    return cell;
}

// 点击代理回调
- (void)CWCarousel:(CWCarousel *)carousel didSelectedAtIndex:(NSInteger)index {
    NSLog(@"...%ld...", index);
}

// 轮播图个数
- (NSInteger)numbersForCarousel {
    return kCount;
}
  1. 为了流畅性和避免概率图片位置错乱问题,当开启自动滚动时,在banner所处的控制器生命周期中需要调用以下对应方法
/**
轮播图所处控制器WillAppear方法里调用
*/
- (void)controllerWillAppear;

/**
轮播图所处控制器WillDisAppear方法里调用
*/
- (void)controllerWillDisAppear;
  • 具体UI样式修改都有具体的属性,详情请查看对应类的.h文件即可.
  • 如有问题和bug,欢迎指正.

cwcarousel's People

Contributors

baozoudiudiu avatar baozouxiaodiudiu avatar

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.