滑动 CollectionView 图片混乱问题
来源:互联网 发布:eclipse端口号 编辑:程序博客网 时间:2024/05/21 09:05
在开发中我遇到一个问题就是滑动 CollectionView 图片混乱问题
项目首页我用一个 Collectionview 实现三个分组,并且实现 cell 大小不一致的分配,但是在我滑动 Collectionview 的时候,第一组左边那两张大图片大小一直在变,而且其他图片也发生了的错乱,如图
用尽各种方法终于找到了解决办法,来给大家分享一下,希望对小伙伴以后的开发有帮助
1、第一组的 cell 我注册了两次,但是注意:cellId 是不一样的
//第一组左边两个图片 [_collectionView registerClass:[XLNewProductCollectionViewCell class] forCellWithReuseIdentifier:@"myCell1-1"]; //第一组其他图片 [_collectionView registerClass:[XLNewProductCollectionViewCell class] forCellWithReuseIdentifier:@"myCell1-2"];
static NSString *cellId11 = @"myCell1-1"; static NSString *cellId12 = @"myCell1-2"; static NSString *cellId2 = @"myCell2"; static NSString *cellId3 = @"myCell3"; if (indexPath.section == 0) { if (indexPath.row % 4 == 0) { //第一组左边两个图片 XLNewProductCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellId11 forIndexPath:indexPath]; return cell; }else{ //第一组其他图片 XLNewProductCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellId12 forIndexPath:indexPath]; return cell; } }else if (indexPath.section == 1){ XLHotProductCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellId2 forIndexPath:indexPath]; return cell; }else{ XLRecommedCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellId3 forIndexPath:indexPath]; return cell; }
3、最后在代理方法中实现 Item 大小的设置
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.section == 0) { if (indexPath.row % 4 == 0) { //第一组左边两张图片 Item 的大小 return CGSizeMake((SCREEN_W-3)/5*2, 90); }else{ //第一组其他图片 Item 大小 return CGSizeMake((SCREEN_W-4.5)/5, 90); } }else if (indexPath.section == 1){ return CGSizeMake((SCREEN_W-60)/3, (SCREEN_W-60)/3+30); }else{ return CGSizeMake((SCREEN_W-55)/2, (SCREEN_W-55)/2+5); }}
修改之后的效果图如下
如果觉得有用,请不要吝啬自己的手,帮忙顶一个,嘿嘿。
如果有更好的办法,欢迎大家来分享
1 0
- 滑动 CollectionView 图片混乱问题
- 关于listview上下滑动imageview图片混乱问题
- 关于ListView滑动混乱问题
- 关于GridView加载和滑动时造成的图片混乱问题总结
- 关于GridView加载和滑动时造成的图片混乱问题总结
- 关于GridView加载和滑动时造成的图片混乱问题总结
- 在使用Recyclerview加载列表圆形图片时出现的滑动卡顿及图片混乱问题
- iOS collectionView相册滑动
- ListView异步加载图片混乱问题
- 解决ListView中滑动复用时控件的混乱问题
- RecyclerView+checkbox滑动导致复用混乱问题的解决方案
- listview 滑动混乱
- collectionView 两列横向滑动
- 解决CollectionView的内容小于它的高度不能滑动的问题
- listView图文显示! 并且简单解决一下图片混乱问题
- Android ListView滑动混乱解决方法
- tableView内置collectionView,动态添加collectionView图片出现图片重叠
- Swift中用CollectionView做广告栏滑动效果
- 关于double转string出现科学计数法的问题
- 多进程与多线程的区别与选择(转强力推荐)
- 手把手教你使用Git
- linux基础之completion
- react native 自定义基础组件
- 滑动 CollectionView 图片混乱问题
- GOF23的一些总结(十九)
- CTF解题笔记(1)
- Sphinx 的介绍和原理探索
- 移动互联培训总结
- GO语言学习笔记-170109
- js 数组的应用
- 自定义带提示的文本输入框
- Android录屏的三种方案