CWCarousel
基于collectionView實現(xiàn)的通用無限輪播圖封裝.
- issues里面的可以重現(xiàn)的問題已經(jīng)修復(fù).
- 部分不能重現(xiàn)的問題暫未處理.
- 請大家提issue盡量描述詳細(xì)些,最好能提供代碼或者截圖.請附上是OC版本還是Swift版本的問題.
- 謝謝配合,大家一起進(jìn)步.
- 代碼示例為oc代碼, 項目中已有swift版本,請自行下載.
- oc版本支持cocoaPods安裝
pod search OC_CWCarousel
oc版和swift是兩份完全不同的代碼昔案,所以代碼實現(xiàn)不盡相同尿贫。有些可能在其中一個版本實現(xiàn)了,但是另一個版本不一定來得及實現(xiàn)爱沟。請參照下面的版本記錄自行了解:
OC:版本記錄
版本號 | 更新內(nèi)容 |
---|---|
1.1.9 | 1帅霜、采用 NSTimer + NSProxy方式實現(xiàn)自動輪播匆背,外部可以無需再手動調(diào)用releaseTimer方法來釋放內(nèi)存了呼伸。<br /> 2、優(yōu)化了scrollToIndex內(nèi)部實現(xiàn) <br /> 3、修改pageControl布局代理的觸發(fā)邏輯 |
1.1.8 | 1. 代碼重構(gòu)括享。<br />2. 計算間距算法修改搂根,更好更簡單的設(shè)置間距。<br />3. 新增代理回調(diào):- (void)CWCarousel:(CWCarousel*)carousel addPageControl:(UIView* )pageControl; 可以在該回調(diào)中自定義布局pageControl铃辖。<br />4. 新增滾動到指定位置方法:- (void*scrollTo:(NSInteger)index animation:(BOOL)animation ;剩愧。<br />5. 廢棄了maxScale 屬性。<br />6.優(yōu)化了自定義pageControl的實現(xiàn)娇斩。<br />7.修改了演示demo首頁樣式和邏輯仁卷。 |
1.1.7 | 適配iOS14 感謝milletZZ |
1.1.5 | 1.新增了2個代理回調(diào) 2.點擊事件代理回調(diào)邏輯優(yōu)化 |
1.1.4 | 修復(fù)樣式3在320尺寸屏幕上可能出現(xiàn)的問題 |
1.1.3 | 提升了一個版本號 |
1.1.2 | 控件優(yōu)化 |
1.1.1 | 添加了無限輪播功能開關(guān) endless |
1.1.0 | 修復(fù)了之前的一些bug |
swift:版本記錄
版本號 | 更新內(nèi)容 |
---|---|
1.1.9 | 1、代碼重構(gòu) 2犬第、timer實現(xiàn)方式優(yōu)化锦积,外部無需手動調(diào)用releaseTimer釋放內(nèi)存 3、計算間距算法修改歉嗓,更好更簡單的設(shè)置間距 4丰介、新增滾動到指定位置方法 |
1.1.8 | 1.fix bug,2. 自定義pageControl優(yōu)化鉴分, 3.只有一張圖時不可無限滑動哮幢, 4.無數(shù)據(jù)時可以設(shè)置占位視圖 |
1.1.7 | 適配iOS14 感謝milletZZ |
1.1.4 | 修復(fù)通過layout創(chuàng)建視圖,偶現(xiàn)不自動輪播問題. |
1.1.3 | 適配swift5.0 |
1.1.2 | 修復(fù)樣式3在320尺寸屏幕上可能出現(xiàn)的問題 |
1.1.1 | 添加了無限輪播功能開關(guān) endless |
1.1.0 | 功能同OC版 1.1.0 |
example.gif
- 目前支持4種樣式
typedef NS_ENUM(NSUInteger, CWCarouselStyle) {
CWCarouselStyle_Unknow = 0, ///<未知樣式
CWCarouselStyle_Normal, ///<普通樣式,一張圖占用整個屏幕寬度
CWCarouselStyle_H_1, ///<自定義樣式一, 中間一張居中,前后2張圖有部分內(nèi)容在屏幕內(nèi)可以預(yù)覽到
CWCarouselStyle_H_2, ///<自定義樣式二, 中間一張居中,前后2張圖有部分內(nèi)容在屏幕內(nèi)可以預(yù)覽到,并且中間一張圖正常大小,前后2張圖會縮放
CWCarouselStyle_H_3, ///<自定義樣式三, 中間一張居中,前后2張圖有部分內(nèi)容在屏幕內(nèi)可以預(yù)覽到,中間一張有放大效果,前后2張正常大小
};
CWCarouselStyle_Normal
normal.gif
CWCarouselStyle_H_1
H_1.gif
CWCarouselStyle_H_2
H_2.gif
CWCarouselStyle_H_3
H_3.gif
- 控件實例對象創(chuàng)建
- 創(chuàng)建flowLayout對象,設(shè)置輪播圖風(fēng)格
/**
構(gòu)造方法
@param style 輪播圖風(fēng)格
@return 實例對象
*/
- (instancetype)initWithStyle:(CWCarouselStyle)style;
// egg:
CWFlowLayout *flowLayout = [[CWFlowLayout alloc] initWithStyle:[self styleFromTag:tag]];
- 創(chuàng)建容器對象
/**
創(chuàng)建實例構(gòu)造方法
@param frame 尺寸大小
@param delegate 代理
@param datasource 數(shù)據(jù)源
@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];
- 注冊自定義cell,并實現(xiàn)代理方法,刷新視圖
[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;
}
// 點擊代理回調(diào)
- (void)CWCarousel:(CWCarousel *)carousel didSelectedAtIndex:(NSInteger)index {
NSLog(@"...%ld...", index);
}
// 輪播圖個數(shù)
- (NSInteger)numbersForCarousel {
return kCount;
}
- 為了流暢性和避免概率圖片位置錯亂問題,當(dāng)開啟自動滾動時,在banner所處的控制器生命周期中需要調(diào)用以下對應(yīng)方法
/**
輪播圖所處控制器WillAppear方法里調(diào)用
*/
- (void)controllerWillAppear;
/**
輪播圖所處控制器WillDisAppear方法里調(diào)用
*/
- (void)controllerWillDisAppear;
- 具體UI樣式修改都有具體的屬性,詳情請查看對應(yīng)類的.h文件即可.
- 如有問題和bug,歡迎指正.