iCarousel 示例(iCarousel 自带样式)
来源:互联网 发布:java 时区时间转换 编辑:程序博客网 时间:2024/05/31 19:34
关于 iCarousel 自带效果示例
#import <iCarousel.h>#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.heigh@interface ViewController ()<iCarouselDataSource,iCarouselDelegate>@property (nonatomic, strong) iCarousel *carouselView;@property (nonatomic, strong) NSMutableArray *arrItems;@property (nonatomic, strong) UIBarButtonItem *btnSelectType;@property (nonatomic, assign) iCarouselType carouselType;@end
viewDidLoad 中实现
self.title = @"iCarouselTypeLinear"; self.view.backgroundColor = [UIColor blackColor];[self.view addSubview:self.carouselView];self.navigationItem.rightBarButtonItem = self.btnSelectType;
返回 item 数量
- (NSInteger)numberOfItemsInCarousel:(iCarousel *)carousel{ return self.arrItems.count;}
返回 item 上视图
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(nullable UIView *)view{ UILabel *label = nil; //create new view if no view is available for recycling if (view == nil) { view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 200.0f)]; ((UIImageView *)view).image = [UIImage imageNamed:@"page.png"]; view.contentMode = UIViewContentModeCenter; label = [[UILabel alloc] initWithFrame:view.bounds]; label.backgroundColor = [UIColor clearColor]; label.textAlignment = NSTextAlignmentCenter; label.font = [label.font fontWithSize:50]; label.tag = 1; [view addSubview:label]; } else { //get a reference to the label in the recycled view label = (UILabel *)[view viewWithTag:1]; } //set item label //remember to always set any properties of your carousel item //views outside of the `if (view == nil) {...}` check otherwise //you'll get weird issues with carousel item content appearing //in the wrong place in the carousel label.text = [self.arrItems[index] stringValue]; return view;}
item 点击事件
- (void)carousel:(iCarousel *)carousel didSelectItemAtIndex:(NSInteger)index{ NSNumber *item = (self.arrItems)[index]; NSLog(@"Tapped view number: %@", item);}
可选项设置
- (CGFloat)carousel:(iCarousel *)_carousel valueForOption:(iCarouselOption)option withDefault:(CGFloat)value{ //customize carousel display switch (option) { case iCarouselOptionSpacing: { //add a bit of spacing between the item views return value * 1.05f; } case iCarouselOptionFadeMax: { if (self.carouselView.type == iCarouselTypeCustom) { //set opacity based on distance from camera return 0.0f; } return value; } default: { return value; } }}
占位图实现(可选)
- (NSInteger)numberOfPlaceholdersInCarousel:(iCarousel *)carousel{ //note: placeholder views are only displayed on some carousels if wrapping is disabled return 0;}- (UIView *)carousel:(iCarousel *)carousel placeholderViewAtIndex:(NSInteger)index reusingView:(UIView *)view{ UILabel *label = nil; //create new view if no view is available for recycling if (view == nil) { //don't do anything specific to the index within //this `if (view == nil) {...}` statement because the view will be //recycled and used with other index values later view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 200.0f)]; ((UIImageView *)view).image = [UIImage imageNamed:@"page.png"]; view.contentMode = UIViewContentModeCenter; label = [[UILabel alloc] initWithFrame:view.bounds]; label.backgroundColor = [UIColor clearColor]; label.textAlignment = NSTextAlignmentCenter; label.font = [label.font fontWithSize:50.0f]; label.tag = 1; [view addSubview:label]; } else { //get a reference to the label in the recycled view label = (UILabel *)[view viewWithTag:1]; } //set item label //remember to always set any properties of your carousel item //views outside of the `if (view == nil) {...}` check otherwise //you'll get weird issues with carousel item content appearing //in the wrong place in the carousel label.text = (index == 0)? @"[": @"]"; return view;}
barButton 点击事件
- (void)barSeletType:(UIBarButtonItem *)barBtnSelectType{ UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"" preferredStyle:(UIAlertControllerStyleActionSheet)]; UIAlertAction *actionLinear = [UIAlertAction actionWithTitle:@"" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) { self.carouselType = iCarouselTypeLinear; self.title = @"iCarouselTypeLinear"; [self changeCarouselViewType]; }]; UIAlertAction *actionRotary = [UIAlertAction actionWithTitle:@"iCarouselTypeRotary" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) { self.carouselType = iCarouselTypeRotary; self.title = @"iCarouselTypeRotary"; [self changeCarouselViewType]; }]; UIAlertAction *actionInvertedRotary = [UIAlertAction actionWithTitle:@"iCarouselTypeInvertedRotary" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) { self.carouselType = iCarouselTypeInvertedRotary; self.title = @"iCarouselTypeInvertedRotary"; [self changeCarouselViewType]; }]; UIAlertAction *actionCylinder = [UIAlertAction actionWithTitle:@"iCarouselTypeCylinder" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) { self.carouselType = iCarouselTypeCylinder; self.title = @"iCarouselTypeCylinder"; [self changeCarouselViewType]; }]; UIAlertAction *actionInvertedCylinder = [UIAlertAction actionWithTitle:@"iCarouselTypeInvertedCylinder" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) { self.carouselType = iCarouselTypeInvertedCylinder; self.title = @"iCarouselTypeInvertedCylinder"; [self changeCarouselViewType]; }]; UIAlertAction *actionWheel = [UIAlertAction actionWithTitle:@"iCarouselTypeWheel" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) { self.carouselType = iCarouselTypeWheel; self.title = @"iCarouselTypeWheel"; [self changeCarouselViewType]; }]; UIAlertAction *actionInvertedWheel = [UIAlertAction actionWithTitle:@"iCarouselTypeInvertedWheel" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) { self.carouselType = iCarouselTypeInvertedWheel; self.title = @"iCarouselTypeInvertedWheel"; [self changeCarouselViewType]; }]; UIAlertAction *actionCoverFlow = [UIAlertAction actionWithTitle:@"iCarouselTypeCoverFlow" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) { self.carouselType = iCarouselTypeCoverFlow; self.title = @"iCarouselTypeCoverFlow"; [self changeCarouselViewType]; }]; UIAlertAction *actionCoverFlow2 = [UIAlertAction actionWithTitle:@"iCarouselTypeCoverFlow2" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) { self.carouselType = iCarouselTypeCoverFlow2; self.title = @"iCarouselTypeCoverFlow2"; [self changeCarouselViewType]; }]; UIAlertAction *actionTimeMachine = [UIAlertAction actionWithTitle:@"iCarouselTypeTimeMachine" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) { self.carouselType = iCarouselTypeTimeMachine; self.title = @"iCarouselTypeTimeMachine"; [self changeCarouselViewType]; }]; UIAlertAction *actionInvertedTimeMachine = [UIAlertAction actionWithTitle:@"iCarouselTypeInvertedTimeMachine" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) { self.carouselType = iCarouselTypeInvertedTimeMachine; self.title = @"iCarouselTypeInvertedTimeMachine"; [self changeCarouselViewType]; }]; [alertController addAction:actionLinear]; [alertController addAction:actionRotary]; [alertController addAction:actionInvertedRotary]; [alertController addAction:actionCylinder]; [alertController addAction:actionInvertedCylinder]; [alertController addAction:actionWheel]; [alertController addAction:actionInvertedWheel]; [alertController addAction:actionCoverFlow]; [alertController addAction:actionCoverFlow2]; [alertController addAction:actionTimeMachine]; [alertController addAction:actionInvertedTimeMachine]; [self.navigationController presentViewController:alertController animated:YES completion:nil];}- (void)changeCarouselViewType{ [UIView beginAnimations:nil context:nil]; self.carouselView.type = self.carouselType; [UIView commitAnimations];}
//- (CATransform3D)carousel:(iCarousel *)_carousel itemTransformForOffset:(CGFloat)offset baseTransform:(CATransform3D)transform//{// //implement 'flip3D' style carousel// transform = CATransform3DRotate(transform, M_PI / 8.0f, 0.0f, 1.0f, 0.0f);// return CATransform3DTranslate(transform, 0.0f, 0.0f, offset * self.carouselView.itemWidth);//}
懒加载
- (iCarousel *)carouselView{ if (!_carouselView) { _carouselView = [[iCarousel alloc] initWithFrame:self.view.frame]; _carouselView.delegate = self; _carouselView.dataSource = self; _carouselView.type = iCarouselTypeLinear; } return _carouselView;}- (NSMutableArray *)arrItems{ if (!_arrItems) { _arrItems = [[NSMutableArray alloc] init]; for (NSInteger i = 0; i < 15; i++) { [_arrItems addObject:@(i)]; } } return _arrItems;}- (UIBarButtonItem *)btnSelectType{ if (!_btnSelectType) { _btnSelectType = [[UIBarButtonItem alloc] initWithTitle:@"Select" style:(UIBarButtonItemStylePlain) target:self action:@selector(barSeletType:)]; } return _btnSelectType;}
linear 效果:
rotary 效果图:
invertedRotary 效果图:
cylinder 效果图:
invertedCylinder 效果图:
wheel 效果图:
invertedWheel 效果图:
coverFlow 效果图:
coverFlow2 效果图:
timeMachine 效果图:
invertedTimeMachine 效果图:
阅读全文
0 0
- iCarousel 示例(iCarousel 自带样式)
- iCarousel
- iCarousel
- [转载]iCarousel
- iCarousel效果
- iCarousel详解
- iCarousel详解
- iOS:iCarousel.h
- iOS开源类iCarousel介绍
- iCarousel详细说明
- 两个iCarousel联动
- iOS 第三方库 - iCarousel
- iOS 旋转木马切换视图 iCarousel
- iCarousel图片乱序问题的解决办法
- 比较牛的控件 猎豹 iCarousel
- iCarousel类-分页滚动视图应用
- 使用iCarousel的旋转木马效果请求图片
- iOS9多任务管理器效果iCarousel高级教程
- request.getParameter 乱码问题
- surfaceflinger create layer and how consumer works
- ajax下载文件
- cc2541简介
- Hadoop和大数据
- iCarousel 示例(iCarousel 自带样式)
- 欢迎使用CSDN-markdown编辑器
- 地址解析协议ARP和反向地址解析协议RARP
- Docker学习笔记(2)
- php上传文件 中文文件名乱码 和 mkdir创建多级目录
- EditText之显示输入字符数量的输入框
- Python 中 Iterator(迭代器)和Iterable(可迭代)的区别:
- JavaScript之动态改变img标签里面的src属性实现图片的循环切换
- 教你如何开启/关闭ubuntu防火墙