iCarousel - 圖片輪播

開(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,車(chē)輪,扇形,影響比較大。
         iCarouselTypeInvertedWheel,車(chē)輪,扇形,影響比較大。
         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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容