在iOs上是否有图像缓存框架? [英] Is there a framework for image caching on iOs?

查看:137
本文介绍了在iOs上是否有图像缓存框架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在使用AFNetworking进行异步图像下载。我想知道是否有存储磁盘或核心数据的方法,我应该调查SDWebImage吗?或者您建议使用自定义解决方案。
基本上我想有一种非常透明的方式来从网址获取图像,所以首先在NSCache中查找它们,如果没有找到磁盘(或核心数据)l则如果再次找不到则下载异步。
感谢您的任何想法

I'm already using AFNetworking for async image download. I was wondering if there's a way for storing on disk or Core Data, should I investigate SDWebImage for that? Or you would suggest to have a custom solution. Basically I would like to have a very transparent way to get images from a url, so first look for them in a NSCache, if not found look on disk (or Core Data)l if not found again download async. Thanks for any idea

推荐答案

SDWebImage已经证明是非常可靠的异步图像提取和缓存实现。

SDWebImage has proven to be a really solid implementation of async image fetching and caching.

如果您使用网页图片获取按钮或图像视图,您甚至可以调用 - (void)setImageWithURL:(NSURL *)url 将检查缓存,为您获取图像的方法,如果不存在,它将异步下载并在设置之前将其存储在缓存中。

If you're using your web images for buttons or imageviews you can even call the -(void)setImageWithURL:(NSURL *)url methods that will check the cache, get the image for you and if it's not there, it will async download it and store it in the cache before setting it.

如果你需要其他东西的图​​像,你仍然可以通过调用以下方法从这个库中受益:

If you need the images for some other stuff, you can still benefit from this library by calling :

SDWebImageManager *manager = [SDWebImageManager sharedManager];

// Remove in progress downloader from queue
[manager cancelForDelegate:self];

[manager downloadWithURL:yourURL delegate:self options:0];

并稍后在委托方法中检索图像:

and retrieving the image later on the delegate method:

- (void)webImageManager:(SDWebImageManager *)imageManager didFinishWithImage:(UIImage *)image
{
    // Do something with the image
}

请注意

- (void)downloadWithURL:(NSURL *)url delegate:(id<SDWebImageManagerDelegate>)delegate options:(SDWebImageOptions)options

在尝试下载之前检查缓存,因此每次需要图像时都可以安全地调用它。

does check the cache before attempting to download, so it is safe to call this every time you need an image.

这篇关于在iOs上是否有图像缓存框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆