Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从Swift 2中的缓存图像进行粘性滚动_Swift_Swift2_Uicollectionview_Uicollectionviewcell - Fatal编程技术网

从Swift 2中的缓存图像进行粘性滚动

从Swift 2中的缓存图像进行粘性滚动,swift,swift2,uicollectionview,uicollectionviewcell,Swift,Swift2,Uicollectionview,Uicollectionviewcell,我可以使用此代码在UICollectionView中显示一些图像,但假设单元格为25。当我向下移动到最后一个单元格,然后尝试向上移动到第一个单元格时,图像将再次加载(从缓存中加载,但它仍然显示加载指示器)。 我的手机是iPhone SE,我没有很多应用程序,而且手机运行得很好。如果我将我的应用程序加载到一个旧的iPhone上,上面有很多数据,那么滚动它就会变得很粘,非常烦人。我们如何避免在索引路径项目的集合视图功能单元中发生这种情况 let cell = collectionView.deque

我可以使用此代码在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")
        }
有人有同样的问题吗? 谢谢


仅供参考,我正在使用parse和kingfisher进行缓存

在对UI工具包进行了几天的研究并使用Instruments>Time Profiler分析了我的应用程序之后,我发现,
图像解码
正在主线程上执行。这是一种糟糕的做法。因此,
kingfisher
有一个选项,可以解码背景和我的应用程序上的图像在旧的iPhone上速度快了很多,但还是有点粘。所以我去掉了手机上的圆角,启用了寻呼功能,这样会减慢滚动速度,现在感觉很好

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

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

在对UI工具包进行了几天的研究并使用Instruments>Time Profiler分析了我的应用程序后,我发现
图像解码
正在主线程上执行。这是一个糟糕的做法。因此
翠鸟
有一个选项,可以在后台解码图像,我的应用程序在旧iPhone上运行得更快,但仍然有点慢粘性。所以我去掉了手机上的圆角,启用了寻呼功能,这样会减慢滚动速度,现在感觉很好

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

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