longitachi / ZLPhotoBrowser

Wechat-like image picker. Support select photos, videos, gif and livePhoto. Support edit image and crop video. 微信样式的图片选择器,支持预览/相册内拍照及录视频、拖拽/滑动选择,编辑图片/视频,支持多语言国际化等功能;
MIT License
4.76k stars 963 forks source link

当同时预览多个网络图片时,会导致图片下载进度和展示的图片错乱。 #734

Closed wushengdubai closed 2 years ago

wushengdubai commented 2 years ago

Issue Description

image

Description and Steps

使用自己传入的urlImageLoader下载网络图片,当快速滑动预览的图片,会有多个图片异步下载,此时urlImageLoader是controller持有,回调的进度progress会和当前cell对不上,且停止滑动后,展示的完图片也只是最后下载完的那一张,很可能对应不上;

Info

ZLPhotoBrowser version: e.g. 4.3.2 Device: e.g. iPhone X Device version: e.g. iOS 14.0 Xcode version: e.g. Xcode 13.4

Configuration code of ZLPhotoConfiguration

  let type = self.urlType?(url) ?? ZLURLType.image
  if type == .image {
   let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ZLNetImagePreviewCell.zl_identifier(), for: indexPath) as! ZLNetImagePreviewCell
        var targetImageView: UIImageView!
        if url.absoluteString.isGifURLString {
                    cell.preview.makeGIFVisible(true)
                    targetImageView = cell.preview.gifImageView
                } else {
                    cell.preview.makeGIFVisible(false)
                    targetImageView = cell.preview.normalImageView
                }

                self.urlImageLoader?(url, targetImageView, { [weak cell] (progress) in
                    ZLMainAsync {
                        cell?.progress = progress
                    }
                }, { [weak cell] in
                    ZLMainAsync {
                        cell?.preview.resetSubViewSize()
              }
        })

   baseCell = cell
wushengdubai commented 2 years ago

是cell重用的问题导致的,只会生成3个cell,当同时下载图片超过3个时,cell重用,设置数据出现问题。

longitachi commented 2 years ago

我试了下demo,demo使用的Kingfisher进行的图片加载,快速滑动不会出现显示错误的情况。 cell复用时,就算给imageView新的图片url,KingFisher会刷新图片对应的taskIdentifier,加载完成后也会判断taskIdentifier是否相等,所以理论上不会出现显示错误的问题