iCarousel - 图片轮播

开源地址:https://github.com/nicklockwood/iCarousel

切换效果比较特别,都不是常见的切换效果,而且不带pageControl。效果可以在上面网址查看。

简单使用

  • 初始化
        _banner = [iCarousel new];
        _banner.type = iCarouselTypeCylinder;// 必须在下面的之前设置,不然需要 reload
        _banner.delegate = self;
        _banner.dataSource = self;

        /*
         typedef NS_ENUM(NSInteger, iCarouselType)
         {
         iCarouselTypeLinear = 0, 平铺,不循环
         iCarouselTypeRotary, 外环,层叠
         iCarouselTypeInvertedRotary,内环,层叠
         iCarouselTypeCylinder, 外环,拼接
         iCarouselTypeInvertedCylinder,内环,拼接
         iCarouselTypeWheel,车轮,扇形,影响比较大。
         iCarouselTypeInvertedWheel,车轮,扇形,影响比较大。
         iCarouselTypeCoverFlow,翻页 不循环
         iCarouselTypeCoverFlow2,翻页2,不循环
         iCarouselTypeTimeMachine,向上堆叠,不循环
         iCarouselTypeInvertedTimeMachine,反堆叠,不循环
         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));
}
 
  • 自己加个 pageControl
// 支持循环的 可用(最后一个的下一个是第0个)
    if (index == [self.dataSource count] - 1) {
        [carousel scrollToItemAtIndex:0 animated:YES];
    } else {
        [carousel scrollToItemAtIndex:index+1 animated:YES];
    }

其他

其他属性和代理有很多。并没有深入使用,自定义3D 转场也是给跪了。一般使用差不多了。待研究。

1

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容