1.创建layout (UICollectionViewFlowLayout)
2.设置layout的方向 默认上下
3.创建UICollectionView
4.设置delegate dataSource 并遵守协议(3个协议)
5.实现dataSource协议里面必须的两个方法
6.创建自定义的Cell类 在cell的初始化方法中把控件创建好
7.注册Cell
8.添加控制组数的协议方法 在dataSourceDelegate里面的第三个
9.添加控制Cell大小的方法
10.添加 行间距为0
11.让collectionView 上来就滚动到第2500组的第0个
12.添加timer 每隔2秒钟 执行一个jumpPage方法
13.在jumpPage方法中 获取当前显示的Cell的位置
14.在当前位置的基础上 让item+1 得到新位置 并让 collectionView滚动到新位置
15.实现scrollViewDelegate的协议方法 在开始拖动的时候 timer停止
16.在拖动结束的时候timer重新开始
- (void)viewDidLoad {
[super viewDidLoad];
UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc]init];
layout.scrollDirection=UICollectionViewScrollDirectionHorizontal;
UICollectionView *cv=[[UICollectionView alloc]initWithFrame:CGRectMake(33, 33, 300, 100) collectionViewLayout:layout];
cv.dataSource=self;
cv.delegate=self;
cv.pagingEnabled=YES;
[self.view addSubview:cv];
// 注册
[cv registerClass:[myCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
// 让collectionview开始时直接移动的位置
[cv scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:500] atScrollPosition:UICollectionViewScrollPositionLeft animated:YES];