開(kāi)源地址:https://github.com/nicklockwood/iCarousel
切換效果比較特別,都不是常見(jiàn)的切換效果板壮,而且不帶pageControl。效果可以在上面網(wǎng)址查看合住。
簡(jiǎn)單使用
- 初始化
_banner = [iCarousel new];
_banner.type = iCarouselTypeCylinder;// 必須在下面的之前設(shè)置绰精,不然需要 reload
_banner.delegate = self;
_banner.dataSource = self;
/*
typedef NS_ENUM(NSInteger, iCarouselType)
{
iCarouselTypeLinear = 0, 平鋪,不循環(huán)
iCarouselTypeRotary, 外環(huán)透葛,層疊
iCarouselTypeInvertedRotary,內(nèi)環(huán)笨使,層疊
iCarouselTypeCylinder, 外環(huán),拼接
iCarouselTypeInvertedCylinder,內(nèi)環(huán)僚害,拼接
iCarouselTypeWheel,車輪硫椰,扇形,影響比較大。
iCarouselTypeInvertedWheel,車輪最爬,扇形,影響比較大门岔。
iCarouselTypeCoverFlow,翻頁(yè) 不循環(huán)
iCarouselTypeCoverFlow2,翻頁(yè)2爱致,不循環(huán)
iCarouselTypeTimeMachine,向上堆疊,不循環(huán)
iCarouselTypeInvertedTimeMachine,反堆疊寒随,不循環(huán)
iCarouselTypeCustom
};
*/
- 常用代理
-(NSInteger)numberOfItemsInCarousel:(iCarousel *)carousel{
return [self.dataSource count];
}
-(UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view{
if (view == nil) {
UIView *colorView = [UIView new];
colorView.backgroundColor = self.dataSource[index];
colorView.frame = CGRectMake(0, 0, 300, CGRectGetHeight(carousel.bounds));
return colorView;
}else{
view.backgroundColor = self.dataSource[index];
return view;
}
return nil;
}
- (void)carousel:(__unused iCarousel *)carousel didSelectItemAtIndex:(NSInteger)index {
NSLog(@"Tapped view number: %ld", (long)index);
}
- (void)carouselCurrentItemIndexDidChange:(__unused iCarousel *)carousel {
NSLog(@"Index: %@", @(self.banner.currentItemIndex));
}
- 自己加個(gè) pageControl
// 支持循環(huán)的 可用(最后一個(gè)的下一個(gè)是第0個(gè))
if (index == [self.dataSource count] - 1) {
[carousel scrollToItemAtIndex:0 animated:YES];
} else {
[carousel scrollToItemAtIndex:index+1 animated:YES];
}
其他
其他屬性和代理有很多糠悯。并沒(méi)有深入使用,自定義3D 轉(zhuǎn)場(chǎng)也是給跪了妻往。一般使用差不多了互艾。待研究。
1