如何获取使用SDWebImage(iOS)缓存的图像的文件系统路径

前端之家收集整理的这篇文章主要介绍了如何获取使用SDWebImage(iOS)缓存的图像的文件系统路径前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在iOS应用程序中使用 SDWebImageUICollectionView进行图像缓存.

一切都很好,但是,当用户在集合视图上快速滚动时,在使用缓存的图像替换占位符之前总是暂停一下.我相信这是由于缓存检查.为了获得更好的用户体验,我希望单元格在实际缓存图像后显示正确的图像而不是占位符.如果我可以获得缓存图像的本地(设备)文件系统路径并将其存储在Show实例中,并使用它(如果存在)而不是我的占位符,这将很容易.

有可能到pass success block to the setImageWithURL method但是,它得到的唯一参数是UIImage实例(实际上在master分支中也有一个名为cached的BOOL变量也被传递).那么 – 是否有可能直接从UIImage实例获取图像的文件系统路径?或者我应该修改SDWebImage,以便将该信息传递给缓存实例?或者有没有更好的方法来实现我之前描述的目标?

我的Show类有imageURL,这里是show cell使用SDWebImage的方法

#import "ShowCell.h"
#import <SDWebImage/UIImageView+WebCache.h>

@implementation ShowCell

@synthesize imageView = _imageView;
@synthesize label = _label;
@synthesize show = _show;

- (void)setShow:(Show *)show
{
    if (_show != show) {
        self.label.text = show.title;
        if (show.imageURL) {
            [self.imageView setImageWithURL:[NSURL URLWithString:show.imageURL]
                           placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
        }
        _show = show;
    }
}

@end@H_404_9@

解决方法

我遇到了类似的问题,请参阅: SDWebImage showing placeholder for images in cache

基本上我分叉项目来解决这个问题.

更新:

您可以这样做以避免闪烁(这适用于项目的主分支):

[imageView setImageWithURL:url placeholderImage:imageView.image options:0 
 progress:^(NSUInteger receivedSize,long long expectedSize) {
        imageView.image = [UIImage imageNamed:@"QuestionMarkFace.png"];
 } completed:nil];@H_404_9@
原文链接:https://www.f2er.com/iOS/335201.html

猜你在找的iOS相关文章