{"id":28089329,"url":"https://github.com/baozoudiudiu/cwcarousel","last_synced_at":"2025-05-13T12:56:44.825Z","repository":{"id":55163730,"uuid":"132012487","full_name":"baozoudiudiu/CWCarousel","owner":"baozoudiudiu","description":"轮播图banner","archived":false,"fork":false,"pushed_at":"2021-10-28T06:55:44.000Z","size":11478,"stargazers_count":289,"open_issues_count":10,"forks_count":56,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-25T01:17:24.472Z","etag":null,"topics":["banner","carousel","objective-c","swift"],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/baozoudiudiu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-03T15:08:33.000Z","updated_at":"2025-04-15T07:18:38.000Z","dependencies_parsed_at":"2022-08-14T14:11:18.311Z","dependency_job_id":null,"html_url":"https://github.com/baozoudiudiu/CWCarousel","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baozoudiudiu%2FCWCarousel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baozoudiudiu%2FCWCarousel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baozoudiudiu%2FCWCarousel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baozoudiudiu%2FCWCarousel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/baozoudiudiu","download_url":"https://codeload.github.com/baozoudiudiu/CWCarousel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253948346,"owners_count":21988953,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["banner","carousel","objective-c","swift"],"created_at":"2025-05-13T12:56:44.049Z","updated_at":"2025-05-13T12:56:44.812Z","avatar_url":"https://github.com/baozoudiudiu.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CWCarousel \n\n## 基于collectionView实现的通用无限轮播图封装.\n\n\u003e 1. issues里面的可以重现的问题已经修复.\n\u003e 2. 部分不能重现的问题暂未处理.\n\u003e 3. 请大家提issue尽量描述详细些,最好能提供代码或者截图.请附上是OC版本还是Swift版本的问题.\n\u003e 4. 谢谢配合,大家一起进步.\n\u003e 5. 代码示例为oc代码, 项目中已有swift版本,请自行下载. \n\u003e 6. oc版本支持cocoaPods安装 `pod search OC_CWCarousel`\n\noc版和swift是两份完全不同的代码，所以代码实现不尽相同。有些可能在其中一个版本实现了，但是另一个版本不一定来得及实现。请参照下面的版本记录自行了解：\n\n#### OC：版本记录\n![oc演示demo](https://github.com/baozoudiudiu/CWCarousel/blob/master/CWCarouselDemo/oc_demo.png?raw=true)\n\n| 版本号 | 更新内容 |\n| ------ | ------ |\n| 1.1.9 | 1、采用 NSTimer + NSProxy方式实现自动轮播，外部可以无需再手动调用releaseTimer方法来释放内存了。\u003cbr /\u003e 2、优化了scrollToIndex内部实现 \u003cbr /\u003e 3、修改pageControl布局代理的触发逻辑 |\n| 1.1.8 | 1. 代码重构。\u003cbr /\u003e2. 计算间距算法修改，更好更简单的设置间距。\u003cbr /\u003e3. 新增代理回调：`- (void)CWCarousel:(CWCarousel*)carousel addPageControl:(UIView* )pageControl;`可以在该回调中自定义布局pageControl。\u003cbr /\u003e4. 新增滚动到指定位置方法：`- (void*scrollTo:(NSInteger)index animation:(BOOL)animation`;。\u003cbr /\u003e5. 废弃了`maxScale`属性。\u003cbr /\u003e6.优化了自定义pageControl的实现。\u003cbr /\u003e7.修改了演示demo首页样式和逻辑。 |\n| 1.1.7 | 适配iOS14 感谢[milletZZ](https://github.com/milletZZ) |\n| 1.1.5 | 1.新增了2个代理回调\u003cbr/\u003e2.点击事件代理回调逻辑优化 |\n| 1.1.4 | 修复样式3在320尺寸屏幕上可能出现的问题 |\n| 1.1.3 | 提升了一个版本号 |\n| 1.1.2 | 控件优化 |\n| 1.1.1 | 添加了无限轮播功能开关 endless |\n| 1.1.0 | 修复了之前的一些bug |\n\n#### swift：版本记录\n| 版本号 | 更新内容 |\n| ------ | :----- |\n| 1.1.9| 1、代码重构 2、timer实现方式优化，外部无需手动调用releaseTimer释放内存 3、计算间距算法修改，更好更简单的设置间距 4、新增滚动到指定位置方法|\n| 1.1.8| 1.fix bug，2. 自定义pageControl优化， 3.只有一张图时不可无限滑动， 4.无数据时可以设置占位视图|\n| 1.1.7 | 适配iOS14 感谢[milletZZ](https://github.com/milletZZ) |\n| 1.1.4 | 修复通过layout创建视图,偶现不自动轮播问题. |\n| 1.1.3 | 适配swift5.0 |\n| 1.1.2 | 修复样式3在320尺寸屏幕上可能出现的问题 |\n| 1.1.1 | 添加了无限轮播功能开关 endless |\n| 1.1.0 | 功能同OC版 1.1.0 |\n\n\u003c!--![example.gif](https://github.com/baozoudiudiu/CWCarousel/blob/master/CWCarousel/Sources/example.gif)--\u003e\n![example.gif](https://upload-images.jianshu.io/upload_images/3096223-64b23965562677f7.gif?imageMogr2/auto-orient/strip)\n\n* 目前支持4种样式\n```\ntypedef NS_ENUM(NSUInteger, CWCarouselStyle) {\nCWCarouselStyle_Unknow = 0,     ///\u003c未知样式\nCWCarouselStyle_Normal,         ///\u003c普通样式,一张图占用整个屏幕宽度\nCWCarouselStyle_H_1,            ///\u003c自定义样式一, 中间一张居中,前后2张图有部分内容在屏幕内可以预览到\nCWCarouselStyle_H_2,            ///\u003c自定义样式二, 中间一张居中,前后2张图有部分内容在屏幕内可以预览到,并且中间一张图正常大小,前后2张图会缩放\nCWCarouselStyle_H_3,            ///\u003c自定义样式三, 中间一张居中,前后2张图有部分内容在屏幕内可以预览到,中间一张有放大效果,前后2张正常大小\n};\n```\n\u003e CWCarouselStyle_Normal\n\n\u003c!--![normal.gif](https://github.com/baozoudiudiu/CWCarousel/blob/master/CWCarousel/Sources/normal.gif)--\u003e\n![normal.gif](https://upload-images.jianshu.io/upload_images/3096223-7a745a375cf86b75.gif?imageMogr2/auto-orient/strip)\n\n\u003e CWCarouselStyle_H_1\n\n\u003c!--![H_1.gif](https://github.com/baozoudiudiu/CWCarousel/blob/master/CWCarousel/Sources/H_1.gif)--\u003e\n![H_1.gif](https://upload-images.jianshu.io/upload_images/3096223-04925d699694000a.gif?imageMogr2/auto-orient/strip)\n\u003e CWCarouselStyle_H_2\n\n\u003c!--![H_2.gif](https://github.com/baozoudiudiu/CWCarousel/blob/master/CWCarousel/Sources/H_2.gif)--\u003e\n![H_2.gif](https://upload-images.jianshu.io/upload_images/3096223-158f78ab0329288e.gif?imageMogr2/auto-orient/strip)\n\n\u003e CWCarouselStyle_H_3\n\n\u003c!--![H_3.gif](https://github.com/baozoudiudiu/CWCarousel/blob/master/CWCarousel/Sources/H_3.gif)--\u003e\n![H_3.gif](https://upload-images.jianshu.io/upload_images/3096223-39307907361b1e4d.gif?imageMogr2/auto-orient/strip)\n\n* 控件实例对象创建\n1. 创建flowLayout对象,设置轮播图风格\n```\n/**\n构造方法\n\n@param style 轮播图风格\n@return 实例对象\n*/\n- (instancetype)initWithStyle:(CWCarouselStyle)style;\n\n// egg:\nCWFlowLayout *flowLayout = [[CWFlowLayout alloc] initWithStyle:[self styleFromTag:tag]];\n```\n2. 创建容器对象\n```\n/**\n创建实例构造方法\n\n@param frame 尺寸大小\n@param delegate 代理\n@param datasource 数据源\n@param flowLayout 自定义flowlayout\n@return 实例对象\n*/\n- (instancetype _Nullable )initWithFrame:(CGRect)frame\n                                delegate:(id\u003cCWCarouselDelegate\u003e _Nullable)delegate\n                              datasource:(id\u003cCWCarouselDatasource\u003e _Nullable)datasource\n                              flowLayout:(nonnull CWFlowLayout *)flowLayout;\n\n// egg:\nCWCarousel *carousel = [[CWCarousel alloc] initWithFrame:self.animationView.bounds\n                                                delegate:self\n                                              datasource:self\n                                              flowLayout:flowLayout];\n```\n3. 注册自定义cell,并实现代理方法,刷新视图\n```\n[carousel registerViewClass:[UICollectionViewCell class] identifier:@\"cellId\"];\n[carousel freshCarousel];\n\n#pragma mark - Delegate\n// 每个轮播图cell样式\n- (UICollectionViewCell *)viewForCarousel:(CWCarousel *)carousel indexPath:(NSIndexPath *)indexPath index:(NSInteger)index{\n    UICollectionViewCell *cell = [carousel.carouselView dequeueReusableCellWithReuseIdentifier:@\"cellId\" forIndexPath:indexPath];\n    /*\n    your code\n    */\n    return cell;\n}\n\n// 点击代理回调\n- (void)CWCarousel:(CWCarousel *)carousel didSelectedAtIndex:(NSInteger)index {\n    NSLog(@\"...%ld...\", index);\n}\n\n// 轮播图个数\n- (NSInteger)numbersForCarousel {\n    return kCount;\n}\n```\n\n4. 为了流畅性和避免概率图片位置错乱问题,当开启自动滚动时,在banner所处的控制器生命周期中需要调用以下对应方法\n```\n/**\n轮播图所处控制器WillAppear方法里调用\n*/\n- (void)controllerWillAppear;\n\n/**\n轮播图所处控制器WillDisAppear方法里调用\n*/\n- (void)controllerWillDisAppear;\n```\n* 具体UI样式修改都有具体的属性,详情请查看对应类的.h文件即可. \n* 如有问题和bug,欢迎指正.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaozoudiudiu%2Fcwcarousel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbaozoudiudiu%2Fcwcarousel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaozoudiudiu%2Fcwcarousel/lists"}