记录
https://github.com/nicklockwood/iCarousel
测试自己想要的效果类似 iCarouselTypeInvertedWheel
#import "iCarousel.h"
@interface ViewController ()<iCarouselDataSource,iCarouselDelegate>
/* <#描述#> */
@property (nonatomic, strong) iCarousel * myCarousel;
@property (nonatomic, strong) NSMutableArray * dataSource;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.view addSubview:self.myCarousel];
}
- (iCarousel *)myCarousel {
if (!_myCarousel) {
_myCarousel = [[iCarousel alloc] initWithFrame:CGRectMake(0, 100, self.view.frame.size.width, 200)];
_myCarousel.dataSource = self;
_myCarousel.delegate = self;
_myCarousel.bounces = NO;
_myCarousel.pagingEnabled = YES;
_myCarousel.type = iCarouselTypeInvertedWheel;
_myCarousel.layer.borderColor = UIColor.redColor.CGColor;
_myCarousel.layer.borderWidth = 1;
}
return _myCarousel;
}
#pragma mark - iCarouselDataSource
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel {
return 10;
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view {
if (view == nil) {
view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
view.backgroundColor = UIColor.redColor;
}
return view;
}
#pragma mark - iCarouselDelegate
- (CGFloat)carousel:(iCarousel *)carousel valueForOption:(iCarouselOption)option withDefault:(CGFloat)value
{
switch (option)
{
case iCarouselOptionWrap:
{
return YES;
}
case iCarouselOptionFadeMax:
{
if (carousel.type == iCarouselTypeCustom)
{
return 0.0f;
}
return value;
}
case iCarouselOptionArc:
{
return 2 * M_PI * 0.35;
}
case iCarouselOptionRadius:
{
return value * 1.8;
}
case iCarouselOptionTilt:
{
return 1;
}
case iCarouselOptionSpacing:
{
return value * 1;
}
default:
{
return value;
}
}
}
//- (CATransform3D)carousel:(iCarousel *)carousel itemTransformForOffset:(CGFloat)offset baseTransform:(CATransform3D)transform {
//
// static CGFloat max_sacle = 1.0f;
// static CGFloat min_scale = 0.6f;
// if (offset <= 1 && offset >= -1) {
// float tempScale = offset < 0 ? 1+offset : 1-offset;
// float slope = (max_sacle - min_scale) / 1;
//
// CGFloat scale = min_scale + slope*tempScale;
// transform = CATransform3DScale(transform, scale, scale, 1);
// }else{
// transform = CATransform3DScale(transform, min_scale, min_scale, 1);
// }
//
// return CATransform3DTranslate(transform, offset * self.myCarousel.itemWidth * 1.4, 0.0, 0.0);
//}
- (void)carousel:(iCarousel *)carousel didSelectItemAtIndex:(NSInteger)index {
// [self showHudTipStr:[NSString stringWithFormat:@"点击了第%ld张图片",(long)index]];
}