日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

使用iCarousel的旋转木马效果请求图片

發布時間:2025/4/9 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用iCarousel的旋转木马效果请求图片 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

使用iCarousel的旋轉木馬效果請求圖片

https://github.com/nicklockwood/iCarousel

先看看效果:

源碼如下:

// // RootViewController.m // // Created by YouXianMing on 14-5-16. // Copyright (c) 2014年 Y.X. All rights reserved. // #import "RootViewController.h" #import "iCarousel.h" #import "YXJSON.h" #import "YXGCD.h" #import "SDWebImage.h"// 數據源 #define SOURCE_DATA @"http://www.duitang.com/album/1733789/masn/p/0/50/"@interface RootViewController ()<iCarouselDataSource, iCarouselDelegate>@property (nonatomic, strong) iCarousel *carousel; // iCarousel @property (nonatomic, strong) NSMutableArray *dataArray; // 數據源@end@implementation RootViewController- (void)viewDidLoad {[super viewDidLoad];// 初始化數據源_dataArray = [[NSMutableArray alloc] init];// 初始化iCarouselself.carousel = [[iCarousel alloc] initWithFrame:self.view.bounds];[self.view addSubview:_carousel];_carousel.backgroundColor = [UIColor blackColor];_carousel.type = iCarouselTypeWheel;// 設置代理self.carousel.delegate = self;self.carousel.dataSource = self;// 異步加載數據[[GCDQueue globalQueue] execute:^{// 獲取json數據NSData *data = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:SOURCE_DATA]];// 轉換為字典NSDictionary *dataDic = [YXJSON dictionaryOrArrayWithJSONSData:data];if (dataDic){NSArray *dataArray = dataDic[@"data"][@"blogs"];for (NSDictionary *dic in dataArray){NSLog(@"%@", dic[@"isrc"]);// 存儲數據[_dataArray addObject:dic[@"isrc"]];}}// 主線程更新[[GCDQueue mainQueue] execute:^{// 重新加載carousel [_carousel reloadData];}];}]; }#pragma mark - #pragma mark iCarousel methods - (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel {// 元素個數return [_dataArray count]; }- (UIView *)carousel:(iCarousel *)carouselviewForItemAtIndex:(NSUInteger)index // view的標志reusingView:(UIView *)view // 重用的view {if (view == nil){view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 300.0f, 400.0f)];}// 強行轉換指針UIImageView *pointView = (UIImageView *)view;// 使用SDWebImage異步下載圖片 [pointView setImageWithURL:[NSURL URLWithString:_dataArray[index]]];// 圖片自動適應pointView.contentMode = UIViewContentModeScaleAspectFit;return view; }- (CGFloat)carousel:(iCarousel *)carouselvalueForOption:(iCarouselOption)optionwithDefault:(CGFloat)value {if (option == iCarouselOptionSpacing){return value * 1.1f;}return value; }@end RootViewController.m

以下幾個地方使用了本人自己封裝的類,不開源,看官請自行替換相關方法-_-!

核心的地方如下:

so easy :)

?

?

問:如何實現view的點擊事件?

實現協議方法 - (void)carousel:(iCarousel *)carousel didSelectItemAtIndex:(NSInteger)index; 即可

?

問:如何獲取偏移量?

實現協議,然后如下使用

- (void)carouselDidScroll:(iCarousel *)carousel
{
??? NSLog(@"scrollOffset %f", carousel.scrollOffset);
}

?

?

轉載于:https://www.cnblogs.com/YouXianMing/p/3732577.html

總結

以上是生活随笔為你收集整理的使用iCarousel的旋转木马效果请求图片的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。