SDWebImage常用函数

"加载GIF图"

- (void)loadGIF
{
    NSURL *URL;

    // 加载网络gif图
    URL = [NSURL URLWithString:@"http://photo.l99.com/source/11/1330351552722_cxn26e.gif"];

    // 加载本地gif图
//    URL = [[NSBundle mainBundle] URLForResource:@"money.gif" withExtension:nil];

    [self.imgView sd_setImageWithURL:URL];
}

"监听图片下载进度"

- (void)loadProgress
{
    NSURL *URL = [NSURL URLWithString:@"http://img3.duitang.com/uploads/item/201608/18/20160818212406_XVw4K.jpeg"];

    [self.imgView sd_setImageWithURL:URL placeholderImage:nil options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize) {

        // receivedSize : 接收的图片大小
        // expectedSize : 图片的总大小

        float progress = (float)receivedSize / expectedSize;

        NSLog(@"%zd %zd %f",receivedSize,expectedSize,progress);

    } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        NSLog(@"图片下载完成 %@",image);
    }];
}

"Manager下载图片"

- (void)LoadImageWithManager
{
    NSURL *URL = [NSURL URLWithString:@"http://img3.duitang.com/uploads/item/201608/18/20160818212406_XVw4K.jpeg"];

    [[SDWebImageManager sharedManager] downloadImageWithURL:URL options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize) {
        // receivedSize : 接收的图片大小
        // expectedSize : 图片的总大小

        float progress = (float)receivedSize / expectedSize;

        NSLog(@"%zd %zd %f",receivedSize,expectedSize,progress);
    } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
        self.imgView.image = image;
    }];
}

  • 1.图片文件缓存的时间有多长:1周

    _maxCacheAge = kDefaultCacheMaxCacheAge

  • 2.SDWebImage 的内存缓存是用什么实现的?

    NSCache

  • 3.SDWebImage 的最大并发数是多少?

    maxConcurrentDownloads = 6

  • 4.SDWebImage 支持动图吗?GIF

#import <ImageIO/ImageIO.h>
[UIImage animatedImageWithImages:images duration:duration];
  • 5.SDWebImage是如何区分不同格式的图像的
根据图像数据第一个字节来判断的!
PNG:0x89
JPG:0xFF
GIF:0x47

-6.SDWebImage 缓存图片的名称是怎么确定的!

md5
    如果单纯使用 文件名保存,重名的几率很高!
    使用 MD5 的散列函数!对完整的 URL 进行 md5,结果是一个 32 个字符长度的字符串!
  • 7.SDWebImage 的内存警告是如何处理的!

    利用通知中心观察

    • UIApplicationDidReceiveMemoryWarningNotification 接收到内存警告的通知
      执行 clearMemory 方法,清理内存缓存!
    • UIApplicationWillTerminateNotification 接收到应用程序将要终止通知
      执行 cleanDisk 方法,清理磁盘缓存!
    • UIApplicationDidEnterBackgroundNotification 接收到应用程序进入后台通知
      执行 backgroundCleanDisk 方法,后台清理磁盘!
      通过以上通知监听,能够保证缓存文件的大小始终在控制范围之内!
      clearDisk 清空磁盘缓存,将所有缓存目录中的文件,全部删除! 实际工作,将缓存目录直接删除,再次创建一个同名空目录!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Zok93

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值