SLCCardView 0.1.3

SLCCardView 0.1.3

Maintained by yang666.



  • By
  • WeiKunChao

SLCCardView

Carthage compatible CocoaPods compatible License: MIT

横向滑动卡片视图

pod 'SLCCardView'

正常视图

#import <SLCCardView/SLCNormalCardView.h> 初始化,用法同CollectionView:

- (SLCNormalCardView *)normalCardView {
if (!_normalCardView) {
_normalCardView = [[SLCNormalCardView alloc] initWithFrame:self.view.bounds];
_normalCardView.delegate = self;
_normalCardView.dataSource = self;
_normalCardView.lineSpacing = 15;
_normalCardView.interitemSpacing = 15;
_normalCardView.sectionInsert = UIEdgeInsetsMake(0, 20, 0, 15);
_normalCardView.itemSize = CGSizeMake(300, 500);
_normalCardView.pageEnable = YES;

[_normalCardView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"identify"];
}
return _normalCardView;
}

因为用UICollectionView完成的,注册的类需是UICollectionViewCell类型. 设置个数和视图:

- (NSInteger)SLCNormalCardViewNumberOfItems:(SLCNormalCardView *)cardView {
return 5;
}

- (UICollectionViewCell *)SLCNormalCardView:(SLCNormalCardView *)cardView itemAtIndex:(NSInteger)index {

UICollectionViewCell *cell = [cardView dequeueReusableItemWithReuseIdentifier:@"identify" forIndex:index];

if (index == 0) {
cell.backgroundColor = [UIColor redColor];
}else if (index == 1) {
cell.backgroundColor = [UIColor greenColor];
}else if (index == 2) {
cell.backgroundColor = [UIColor purpleColor];
}else if (index == 3) {
cell.backgroundColor = [UIColor blueColor];
}else if (index == 4) {
cell.backgroundColor = [UIColor blackColor];
}
return cell;
}

代理回调:(点击和正中坐标)

- (void)SLCNormalCardView:(SLCNormalCardView *)cardView didSelectItemAtIndex:(NSInteger)index {
NSLog(@"选了%ld",index);
}

- (void)SLCNormalCardView:(SLCNormalCardView *)cardView currentIndexChanged:(NSInteger)currentIndex {
NSLog(@"变了%ld",currentIndex);
}

Alt text.

当设置loopEnable属性为YES时,开启无限循环. _normalCardView.loopEnable = YES;

Alt text.

当调用autoAnmitionWithDuration:方法,自动滚动.变量是时间间隔.

滑动缩放卡片效果

#import <SLCCardView/SLCAnimationCardView.h> 使用同上:

- (SLCAnimationCardView *)animationView {
if (!_animationView) {
_animationView = [[SLCAnimationCardView alloc] initWithFrame:self.view.bounds];
_animationView.dataSource = self;
_animationView.delegate = self;
_animationView.itemSize = CGSizeMake(300, 500);
_animationView.lineSpacing = 15;
_animationView.interitemSpacing = 15;
_animationView.sectionInsert = UIEdgeInsetsMake(0, 20, 0, 20);
_animationView.widthScale = 0.7;
_animationView.heightScale = 0.8;
_animationView.pageEnable = YES;

[_animationView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"identify"];
}
return _animationView;
}

上述,widthScale属性和heightScale属性分别指放大的那个所占整个的比例.而itemSize指的是正常大小.

布局与代理都同上.

Alt text.