【问题标题】:Sticky scroll from cached images in Swift 2Swift 2中缓存图像的粘性滚动
【发布时间】:2016-08-08 12:41:49
【问题描述】:

我使用此代码在 UICollectionView 中显示一些图像,但可以说单元格是 25。当我下到最后一个单元格然后我尝试上到第一个单元格时,图像再次加载(从缓存但它仍然显示加载指示器。 我的手机是 iPhone SE,我没有很多应用程序,手机运行完美。如果我将我的应用程序加载到上面有很多数据的旧 iphone 上,那么滚动它就会变得粘滞并且非常烦人。我们如何避免在索引路径中的项目的集合视图函数单元格内发生这种情况???

let cell = collectionView.dequeueReusableCellWithReuseIdentifier("RecipesCell", forIndexPath: indexPath) as! RecipesCell    
// Get Cover image
        let myCache = ImageCache(name: recipesClass.objectId!)
        let queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
        let optionInfo: KingfisherOptionsInfo = [
            .DownloadPriority(0.5),
            .CallbackDispatchQueue(queue),
            .Transition(ImageTransition.Fade(1)),
            .TargetCache(myCache)
        ]
        if  let imageFile = recipesClass[RECIPES_COVER] as? PFFile {

        let URL = NSURL(string: imageFile.url!)!

        cell.coverImage.kf_setImageWithURL(URL, placeholderImage: nil,
            optionsInfo: optionInfo,
            progressBlock: { receivedSize, totalSize in
                print("\(indexPath.row + 1): \(receivedSize)/\(totalSize)")
            },
            completionHandler: { image, error, cacheType, imageURL in
                print("\(indexPath.row + 1): Finished")
                print("cacheType: \(cacheType) \(indexPath.row + 1): Finished")
        })

        } else {
             cell.coverImage.image = UIImage(named:"logo")
        }

有人有同样的问题吗? 谢谢!

仅供参考,我正在使用解析和翠鸟进行缓存

【问题讨论】:

    标签: swift swift2 uicollectionview uicollectionviewcell


    【解决方案1】:

    在对 UI Kit 进行研究并使用 Instruments > Time Profiler 分析我的应用程序后,我发现image decoding 正在主线程上执行。这是不好的做法。所以Kingfisher 有一个选项可以解码背景上的图像,我的应用程序在旧 iphone 上运行得更快,但仍然有点粘。所以我去掉了单元格上的圆角并启用了分页,这样它会减慢滚动速度,现在很棒。

    对于背景图像解码,我使用了这个

       let optionInfo: KingfisherOptionsInfo = [
                .DownloadPriority(0.5),
                .CallbackDispatchQueue(queue),
                .Transition(ImageTransition.Fade(1)),
                .TargetCache(myCache),
                .BackgroundDecode //this is the new option I added
            ]
    

    【讨论】:

      猜你喜欢
      • 2021-06-10
      • 1970-01-01
      • 2018-06-11
      • 2016-08-08
      • 2016-03-23
      • 2015-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多