SDWebImage 最新版详解

本文详细介绍SDImageCache组件,包括其核心功能、属性配置及常用方法。该组件支持图片的内存和磁盘缓存管理,提供了丰富的API来实现图片缓存的高效管理。

今天先介绍下 类引用  剩下的会尽快补上  类引用有5个 分别是以下几个 

SDImageCache  图片异步缓存

SDWebImageDownloader   图片异步下载 

SDWebImageDownloaderOperation Class Reference  图片异步下载操作


  • SDWebImageManager 图片管理


    • SDWebImagePrefetcher 图片预处理

    • 一、SDImageCache  图片异步缓存

      概述

    • SDImageCache maintains a memory cache and an optional disk cache. Disk cache write operations are performed asynchronous so it doesn’t add 

    • unnecessary latency to the UI.

    • SDImageCache只要包括维护一个内存缓存和一个可选的磁盘缓存。磁盘高速缓存的写操作被执行异步所以它不会增加不必要的等待时间到用户界面。


    • property
      属性 

    • @property (assign, nonatomic) NSInteger maxCacheAge   以秒为单位 图片保存在内存中的最长时间

    •   maxMemoryCost property    保存在存储器中像素的总和 
        maxCacheAge  maxCacheSize property   在内存中能够存储图片的最大容量 以比特为单位
      + sharedImageCache

    • 创建一个新的缓存空间
      – initWithNamespace:

    • 添加一个只读的缓存路径
      – addReadOnlyCachePath:
      – storeImage:forKey:
      – storeImage:forKey:toDisk:
      – storeImage:recalculateFromImage:imageData:forKey:toDisk:
      – queryDiskCacheForKey:done:
      – imageFromMemoryCacheForKey:
      – imageFromDiskCacheForKey:

    • 删除图片 
      – removeImageForKey:
      – removeImageForKey:withCompletion:
      – removeImageForKey:fromDisk:
      – removeImageForKey:fromDisk:withCompletion:
      – clearMemory       清除缓存
      – clearDiskOnCompletion:
      – clearDisk      清除磁盘
      – cleanDiskWithCompletionBlock:   block回调 在清除磁盘后的操作
      – cleanDisk          清除磁盘
      – getSize          获取缓存的大小  比特  如果想要获取M  可以与1024相除
      – getDiskCount      在磁盘中缓存图片的个数
      – calculateSizeWithCompletionBlock:
      – diskImageExistsWithKey:completion:
      – diskImageExistsWithKey:
      – cachePathForKey:inPath:
      – defaultCachePathForKey:    默认缓存的路径

  • [objc] view plain copy

    [objc] view plain copy


    [objc] view plain copy



  1. //  清除磁盘中的缓存  

  2. [cache cleanDisk];  

  3. //  清除缓存的存储  

  4. [cache clearMemory];  

  5. [self.tableView reloadData];  

  1. //  创建缓存实例  

  2.     cache = [[SDImageCache alloc]init];  

  3.     //  获取sdwebimage的共享单例  

  4.     cache =  [SDImageCache sharedImageCache];  

  5.       

  6.     // 在内存缓存保留的最长时间 以秒为单位计算 为了检测 设置为5秒  

  7.     cache.maxCacheAge = 30;  

  8.     //  在内存中能够存储图片的最大容量 以比特为单位 这里设为1024 也就是1M  

  9.     cache.maxCacheSize = 1024;  

  10.     //  保存在存储器中像素的总和  

  11.     cache.maxMemoryCost = 1000;  

  12.       

  13.       

  14.     //  下载  

  15.     // 创建实例  

  16.     downloaderImage = [SDWebImageDownloader sharedDownloader];  

  17.     //  设置下载的用户名和密码  

  18.     downloaderImage.username = @"yun";  

  19.     downloaderImage.password = @"0628";  

  20.     //  设置下载超时时间  

  21.     downloaderImage.downloadTimeout = 5;  

  22.       

  23.     //  当前的下载量 只读属性  

  24.     NSInteger downloader  = [downloaderImage currentDownloadCount];  

  25.     NSString *downloaderCount = [NSString stringWithFormat:@"%ld",(long)downloader];  

  26.     NSLog(@"downloaderCount = %@",downloaderCount);  

  27.       

  28.       

  29.     NSInteger macDownloader = [SDWebImageDownloader sharedDownloader].maxConcurrentDownloads;  

  30.     NSLog(@",(long)macDownloader = %ld",(long)macDownloader);  

  1. @interface TableViewController (){  

  2.     SDImageCache *cache;  

  3. }  

[objc] view plain copy
  1. //  异步加载图片并缓存  

  2.    [cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://p2.pstatp.com/thumb/1314/2834512236"] placeholderImage:[UIImage imageNamed:@"placeho.jpg"]];  














本文转自ljianbing51CTO博客,原文链接:http://blog.51cto.com/ljianbing/1866674,如需转载请自行联系原作者



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值