使用iCarousel的旋转木马效果请求图片
生活随笔
收集整理的這篇文章主要介紹了
使用iCarousel的旋转木马效果请求图片
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
使用iCarousel的旋轉(zhuǎn)木馬效果請(qǐng)求圖片
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"// 數(shù)據(jù)源 #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; // 數(shù)據(jù)源@end@implementation RootViewController- (void)viewDidLoad {[super viewDidLoad];// 初始化數(shù)據(jù)源_dataArray = [[NSMutableArray alloc] init];// 初始化iCarouselself.carousel = [[iCarousel alloc] initWithFrame:self.view.bounds];[self.view addSubview:_carousel];_carousel.backgroundColor = [UIColor blackColor];_carousel.type = iCarouselTypeWheel;// 設(shè)置代理self.carousel.delegate = self;self.carousel.dataSource = self;// 異步加載數(shù)據(jù)[[GCDQueue globalQueue] execute:^{// 獲取json數(shù)據(jù)NSData *data = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:SOURCE_DATA]];// 轉(zhuǎn)換為字典NSDictionary *dataDic = [YXJSON dictionaryOrArrayWithJSONSData:data];if (dataDic){NSArray *dataArray = dataDic[@"data"][@"blogs"];for (NSDictionary *dic in dataArray){NSLog(@"%@", dic[@"isrc"]);// 存儲(chǔ)數(shù)據(jù)[_dataArray addObject:dic[@"isrc"]];}}// 主線程更新[[GCDQueue mainQueue] execute:^{// 重新加載carousel [_carousel reloadData];}];}]; }#pragma mark - #pragma mark iCarousel methods - (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel {// 元素個(gè)數(shù)return [_dataArray count]; }- (UIView *)carousel:(iCarousel *)carouselviewForItemAtIndex:(NSUInteger)index // view的標(biāo)志reusingView:(UIView *)view // 重用的view {if (view == nil){view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 300.0f, 400.0f)];}// 強(qiáng)行轉(zhuǎn)換指針UIImageView *pointView = (UIImageView *)view;// 使用SDWebImage異步下載圖片 [pointView setImageWithURL:[NSURL URLWithString:_dataArray[index]]];// 圖片自動(dòng)適應(yīng)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以下幾個(gè)地方使用了本人自己封裝的類(lèi),不開(kāi)源,看官請(qǐng)自行替換相關(guān)方法-_-!
核心的地方如下:
so easy :)
?
?
問(wèn):如何實(shí)現(xiàn)view的點(diǎn)擊事件?
實(shí)現(xiàn)協(xié)議方法 - (void)carousel:(iCarousel *)carousel didSelectItemAtIndex:(NSInteger)index; 即可
?
問(wèn):如何獲取偏移量?
實(shí)現(xiàn)協(xié)議,然后如下使用
- (void)carouselDidScroll:(iCarousel *)carousel
{
??? NSLog(@"scrollOffset %f", carousel.scrollOffset);
}
?
?
轉(zhuǎn)載于:https://www.cnblogs.com/YouXianMing/p/3732577.html
總結(jié)
以上是生活随笔為你收集整理的使用iCarousel的旋转木马效果请求图片的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 兼容Mono的下一代云环境Web开发框架
- 下一篇: ajax检查用户名