SDWebImage 最新版详解

<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">SDWebImage 详解  如有不当的地方请大家多多提出宝贵的 意见  谢谢 。。。。</span>

今天先介绍下 类引用  剩下的会尽快补上  类引用有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:    默认缓存的路径


  • @interface TableViewController (){
        SDImageCache *cache;
    }
    
    //  创建缓存实例
        cache = [[SDImageCache alloc]init];
        //  获取sdwebimage的共享单例
        cache =  [SDImageCache sharedImageCache];
        
        // 在内存缓存保留的最长时间 以秒为单位计算 为了检测 设置为5秒
        cache.maxCacheAge = 30;
        //  在内存中能够存储图片的最大容量 以比特为单位 这里设为1024 也就是1M
        cache.maxCacheSize = 1024;
        //  保存在存储器中像素的总和
        cache.maxMemoryCost = 1000;
        
        
        //  下载
        // 创建实例
        downloaderImage = [SDWebImageDownloader sharedDownloader];
        //  设置下载的用户名和密码
        downloaderImage.username = @"yun";
        downloaderImage.password = @"0628";
        //  设置下载超时时间
        downloaderImage.downloadTimeout = 5;
        
        //  当前的下载量 只读属性
        NSInteger downloader  = [downloaderImage currentDownloadCount];
        NSString *downloaderCount = [NSString stringWithFormat:@"%ld",(long)downloader];
        NSLog(@"downloaderCount = %@",downloaderCount);
        
        
        NSInteger macDownloader = [SDWebImageDownloader sharedDownloader].maxConcurrentDownloads;
        NSLog(@",(long)macDownloader = %ld",(long)macDownloader);

            //  清除磁盘中的缓存
            [cache cleanDisk];
            //  清除缓存的存储
            [cache clearMemory];
            [self.tableView reloadData];
    


  •  //  异步加载图片并缓存
        [cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://p2.pstatp.com/thumb/1314/2834512236"] placeholderImage:[UIImage imageNamed:@"placeho.jpg"]];



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值