1

我正在使用imageView.af_setImageWithURL(URL)它,它工作得很好。我没有对图像过滤器做任何事情,我看到了这个注释:

如果不使用图像过滤器,建议将 NSURLCache 的内存容量设置为零,以避免将相同的内容两次存储在内存中。

使用 UIImage 扩展完成此任务的最干净/最小的方法是什么?

4

2 回答 2

2

你的回答肯定会奏效。这是另一种不需要您构建自己的ImageDownloader.

let downloader = UIImageView.af_sharedImageDownloader
let configuration = downloader.sessionManager.session.configuration
configuration.URLCache?.memoryCapacity = 0

这最终会做同样的事情,而不必创建任何新的实例。

于 2016-07-25T04:57:32.747 回答
0

我正在尝试以下操作:

// From https://github.com/Alamofire/AlamofireImage - "If you do not use image filters, it is advised to set the memory capacity of the NSURLCache to zero to avoid storing the same content in-memory twice."
// Note: We're making an educated guess that NSURLCache does not allocate the memory capacity when it's created.. it just uses it as an upper bound. So we'll let ImageDownloader create the session configuration it wants, then we'll just set the memory capacity on its url cache to 0 as suggested.
let configurationWithNoMemoryCapacityOnURLCache = ImageDownloader.defaultURLSessionConfiguration()
configurationWithNoMemoryCapacityOnURLCache.URLCache?.memoryCapacity = 0

UIImageView.af_sharedImageDownloader = ImageDownloader(
    configuration: configurationWithNoMemoryCapacityOnURLCache
)
于 2016-07-24T06:18:11.543 回答