图片无限轮播-最简单的实现方法
来源:互联网 发布:淘宝颜真卿钢笔字帖 编辑:程序博客网 时间:2024/05/21 07:55
collectionView中只有三个cell 每次显示的都是第二个cell
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
CycleViewCell *cell = [collectionViewdequeueReusableCellWithReuseIdentifier:@"Cell"forIndexPath:indexPath];
//indexPath.item - 1 相当于index左移加1 右移减一
//indexPath.item - 1 如果左移就相当于要显示第三个cell 2-1 ,相当于self.currentIndex + 1
//indexPath.item - 1 如果右移就相当于要显示第一个cell 0-1 ,相当于self.currentIndex - 1
NSInteger index = (self.currentIndex + indexPath.item - 1 + self.imageURLs.count) %self.imageURLs.count;
cell.imageURL =self.imageURLs[index];
return cell;
}
// 在滚动视图完全停止滚动后会调用的方法
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
// 1. 根据contentOffset可以判断出停留住的页面
int page = scrollView.contentOffset.x / scrollView.bounds.size.width;
NSLog(@"第 %d页", page);
// 2. 如果是第0页,self.currentIndex - 1,如果是第2页,self.currentIndex +1;
self.currentIndex = (self.currentIndex + page - 1 + self.imageURLs.count) %self.imageURLs.count;
// 3. 让collection滚动会第一个页面
NSIndexPath *indexPath = [NSIndexPathindexPathForItem:1inSection:0];
[self.collectionViewscrollToItemAtIndexPath:indexPathatScrollPosition:UICollectionViewScrollPositionCenteredHorizontallyanimated:NO];
}
- 图片无限轮播-最简单的实现方法
- 最简单的图片轮播实现
- 最简单的本地加载图片无限自动轮播
- 无限轮播的Banner简单方法
- 无限轮播的简单实现
- 网络无限轮播的简单实现
- ImageView实现图片的无限轮播 以及viewpager实现图片的无限轮播
- 无限轮播简单方法
- JavaScript实现最简单的图片轮播
- 图片的无限轮播
- 图片的无限轮播
- 最简单的JS图片轮播
- 最简单的图片轮播
- android 最简单的轮播图片
- 图片轮播器无限轮播的实现思想
- iOS -- 用collectionView实现图片的无限轮播
- 无限轮播的实现
- 无限轮播的实现
- 已迁移到 Techzero 独立博客,欢迎访问!
- 计蒜客课程算法—蒜头学算术(DFS)
- javascript中获取非行间样式的方法。
- 陈力:传智播客古代 珍宝币 泡泡龙游戏开发第42讲:PHP数据库开发案例
- RPC通信功能实现
- 图片无限轮播-最简单的实现方法
- Android 四大组件学习之ContentProvider四
- jstl el 表达式详解
- SQL注入与防范
- ubuntu 删除内核文件
- mybatis 实现一对一关联表查询
- 移动端WEB开发,click,touch,tap事件浅析
- 集合框架
- 30分钟玩转Docker系列课程1---初识Docker