CCCycleView 0.0.3

CCCycleView 0.0.3

ZacksChen 维护。



  • zacks

CCCycleView

一个视图循环器,目前可以用作:

轮播图 视图循环 跑马灯效果
cycleImage cycleView cycleImage

要求

·Xcode8+

·iOS8+

·ARC

安装

CocoaPods

  1. 将 pod 'CCCycleView' 添加到您的 Podfile 中。
  2. 运行 pod install 或 pod update。
  3. 导入 "CCViewScroolView.h"

手动

  1. 下载 CCCycleView 子目录下的所有文件。
  2. 将源文件添加到您的 Xcode 项目中。

使用

使用collectionView作为基础,需要在数据源对象中加入相应的reusekey,以根据数据不同,展示不同的view;还需要返回需要循环播放的view。

1、设置数据源reusekey及参数

NSMutableArray *data = [@[] mutableCopy];
for (int i = 0; i < 10; i++) {
    NSObject *model = [[NSObject alloc] init];
    model.cc_reUseStringKey = @"UIImageView";
    [data addObject:model];
}
self.viewScrollView.viewEdge = UIEdgeInsetsMake(5, 10, 2, 8);
self.viewScrollView.direction = UICollectionViewScrollDirectionHorizontal;
self.viewScrollView.timeInterval = 5.0f;
self.viewScrollView.infinite = YES;
self.viewScrollView.modelArray = data;//数据
self.viewScrollView.dataSource = self;
self.viewScrollView.delegate = self;
self.viewScrollView.userDragEnable = YES;
//回调来给每个view绑定数据
self.viewScrollView.configureViewBlock = ^(UIView *view, id model, NSInteger index) {
    UIImageView *imageView = (UIImageView *)view;
    imageView.image = [UIImage imageNamed:@"0"];
};
[self.viewScrollView layoutNeedUpdate];
[self.viewScrollView reloadData];

2、返回view

- (UIView *)cc_viewForModel:(NSObject *)model
{
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.contentMode = UIViewContentModeScaleAspectFill;
    imageView.clipsToBounds = YES;
    return imageView;
}

当然还有其他参数可以设置

/**
 default is UICollectionViewScrollDirectionHorizontal
 warning:after U change,u should call layoutNeedUpdate
 */
@property (assign, nonatomic) UICollectionViewScrollDirection direction;
/**
 whether user can drag the view
 default is YES
 */
@property (assign, nonatomic,getter=isUserDragEnable) BOOL userDragEnable;
/**
 whether the scroll is infinite
 default is YES
 */
@property (assign, nonatomic,getter=isInfinite) BOOL infinite;
/**
 whether the scroll is pageControl
 default is YES
 */
@property (assign, nonatomic,getter=isPageControl) BOOL pageControl;
/**
 the auto scroll time
 default is 3.0f
 */
@property (assign, nonatomic) NSTimeInterval timeInterval;
/**
 the item padding
 When scrollDirection is horizontal,item padding is right to next's left.
 When scrollDirection is vertical,item padding is bottom to next's top.
 default is 10.0
 warning:after U change,u should call layoutNeedUpdate
 */
@property (assign, nonatomic) CGFloat itemPadding;
/**
 the edge in cell.contentView
 default is UIEdgeInsetsZero
 warning:after U change,u should call layoutNeedUpdate
 */
@property (assign, nonatomic) UIEdgeInsets viewEdge;
/**
 the view Size
 default is (view's height and view's width) * 0.8
 warning:after U change,u should call layoutNeedUpdate
 */
@property (assign, nonatomic) CGSize itemSize;
/**
 the dataSource
 */
@property (strong, nonatomic) NSArray* modelArray;

目前的回调仅暴露了2个方法(如果后期有需要,可以加上)

@protocol CCViewScrollViewDelegate <NSObject>

- (void)cc_scrollDidSelectItem:(NSInteger)index model:(id)model view:(UIView *)view;

- (void)cc_scrollDidScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex;

@end

授权协议

CCCycleView遵循MIT授权协议。

意见反馈

·Email:[email protected]

·Weibo:铁甲陈小宝

·Twitter:zacks_Chen