iOS开发之 collectionView 刷新单个重影问题

在做项目使用collectionView的时候遇到了只需刷新某个cell的情况。按照常规思路去刷新:

  NSIndexPath *topHeaderViewIndexpath = [[self.tableView indexPathsForVisibleRows] firstObject];
        NSIndexPath *moveToIndexpath = [NSIndexPath indexPathForRow:topHeaderViewIndexpath.section inSection:0];
       if (![moveToIndexpath isEqual:self.selectIndex] && self.isclickCollection != YES) {
           NSIndexPath *lastIndex = self.selectIndex;
           self.selectIndex = moveToIndexpath;
               [self.topCollectionView reloadItemsAtIndexPaths:@[lastIndex,moveToIndexpath]];
               [self.topCollectionView selectItemAtIndexPath:moveToIndexpath animated:YES scrollPosition:UICollectionViewScrollPositionLeft];

  
       }

然后发现刷新的时候会有重影,后来改成如下代码成功解决重影问题:

    NSIndexPath *topHeaderViewIndexpath = [[self.tableView indexPathsForVisibleRows] firstObject];
        NSIndexPath *moveToIndexpath = [NSIndexPath indexPathForRow:topHeaderViewIndexpath.section inSection:0];
       if (![moveToIndexpath isEqual:self.selectIndex] && self.isclickCollection != YES) {
           NSIndexPath *lastIndex = self.selectIndex;
           self.selectIndex = moveToIndexpath;

          //解决重影重点
           [UIView performWithoutAnimation:^{
               [self.topCollectionView reloadItemsAtIndexPaths:@[lastIndex,moveToIndexpath]];
               [self.topCollectionView selectItemAtIndexPath:moveToIndexpath animated:YES scrollPosition:UICollectionViewScrollPositionLeft];
           }];

  
       }
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1.ios高性能编程 (1).内层 最小的内层平均值和峰值(2).耗电量 高效的算法和数据结构(3).初始化时...
    欧辰_OSR阅读 29,643评论 8 265
  • 我是黑夜里大雨纷飞的人啊 1 “又到一年六月,有人笑有人哭,有人欢乐有人忧愁,有人惊喜有人失落,有的觉得收获满满有...
    陌忘宇阅读 8,605评论 28 53
  • 信任包括信任自己和信任他人 很多时候,很多事情,失败、遗憾、错过,源于不自信,不信任他人 觉得自己做不成,别人做不...
    吴氵晃阅读 6,226评论 4 8
  • 步骤:发微博01-导航栏内容 -> 发微博02-自定义TextView -> 发微博03-完善TextView和...
    dibadalu阅读 3,181评论 1 3
  • 回这一趟老家,心里多了两个疙瘩。第一是堂姐现在谈了一个有妇之夫,在她的语言中感觉,她不打算跟他有太长远的计划,这让...
    安九阅读 3,532评论 2 4