zoukankan      html  css  js  c++  java
  • SDWebImage笔记

    SDWebImage  

    https://github.com/rs/SDWebImage

    提供一个UIImageView 类别以支持加载来自网络的远程图片。

    具有缓存管理,异步下载,同一个URL下载次数控制和优化等 

    UITableView UIImageView +webCache 类

    UIImageView +WebCache.h   tableView cellForRowAtIndexPath

    static NSString *MyIdentifier = @"MyIdentifier";

    UITableViewCell *cel = [tableView dequeReuseableCellWithIdentifier.MyIdentifier]

    if(cell == nil) {

      cell = 

    }

     

    [cell.imageView setImageWithURL:[NSURL URLWithString:@"htt://www.domain/path/to /image.jpg"]

    placeholderImage:[UIImage imageNamed:@"placeholder.png"];

    cell.textLabel.text = @"MyText";

    return cell;

    SDWebImageManager *manager = [SDWebImageManager sharedManager];

    UIImage *cacheImage = [manager imageWithURL:url];

    if(cachedImage) {

      

    } else {

      [manager downloadWithURL:url delegate:self];

    }

    protocol webImageManager:didFinishWithImage方法

    downloader= [SDWebImageDownloader downloaderWithURL:url delegate:self]

    独立的异步图片缓存

    SDWebImage支持异步的图片下载+缓存

    1 入口setImageWithURL:placeholderImage:option 先把placeholderImage显示后,

    然后SDWebImageManage根据URL开始处理图片

    进入SDWebImageManager-downloadWithURL:delegate:options:userinfo

    交给SDImageCache从缓存查找图片是否已下载

    queryDiskCacheForKey:delegate:userinfo

    先从内存图片查找是否有图片, 如果内存中已经有图片存,

    imageCach:didFindImage:forKey:userInfo

    如果内存中没有,生成NSInvocationOperation 到开始从硬盘查找图片图片是否已 存

    根据URLKey 在硬盘存目录下尝试读取图片,这是NSOperation操作,

    notifyDelegate

    imageCache:didNotFindImageForKey:userinfo

    共享或重新生成一个下载器SDWebImageDownloader开始下载图片。

    下载由NSURLConnection 来做,实现相关delegate 来判断图片下载中。

    connection:didReceiveData:中利用IMageIO做了按图片下载进度加载效果。

    connection:didFinishLoading 数据下载完成后交给SDWebImageDecoder做

    图片解码处理

    NSOperationQueue完成,不会拖慢主线程UI,

    notifyDelegateOnMainThreadWithInfo宣告解码完成,imageDecoder:didFinishDecodingImage:userInfo

    image

    保存到SDImageCache中, 内存存和硬盘缓存同时保存。

    NSInvocationOperation完成,

     

     

  • 相关阅读:
    redis 切换大量的缓存数据
    springboot jdbctemplate 常用的语法
    Spring Boot 整合 jdbctemplate 多数据源
    Spring Boot 整合 jdbctemplate 单数据源
    IDEA(Eclipse) 常用的快捷键(快速开发)
    bigdecimal 类型的变量怎么相互加减乘除
    在js和java中判断手机访问的是ios系统还是android系统
    fiddler抓web请求
    sign和token设计
    移动端自动化测试-Windows-Android-Appium环境搭建
  • 原文地址:https://www.cnblogs.com/yushunwu/p/3133086.html
Copyright © 2011-2022 走看看