美文网首页
iOS开发之 collectionView 刷新单个重影问题

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

作者: 安静SRR | 来源:发表于2021-06-16 14:24 被阅读0次

    在做项目使用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];
               }];
    
      
           }
    

    相关文章

      网友评论

          本文标题:iOS开发之 collectionView 刷新单个重影问题

          本文链接:https://www.haomeiwen.com/subject/aeoxyltx.html