SDWebImage源码阅读SDWebImagePrefetcher
Posted CHM
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SDWebImage源码阅读SDWebImagePrefetcher相关的知识,希望对你有一定的参考价值。
SDWebImagePrefetcherDelegate
1 @protocol SDWebImagePrefetcherDelegate <NSObject> 2 3 @optional 4 5 /** 6 * Called when an image was prefetched. 7 * 8 * @param imagePrefetcher The current image prefetcher 9 * @param imageURL The image url that was prefetched 10 * @param finishedCount The total number of images that were prefetched (successful or not) 11 * @param totalCount The total number of images that were to be prefetched 12 */ 13 - (void)imagePrefetcher:(nonnull SDWebImagePrefetcher *)imagePrefetcher didPrefetchURL:(nullable NSURL *)imageURL finishedCount:(NSUInteger)finishedCount totalCount:(NSUInteger)totalCount; 14 15 /** 16 * Called when all images are prefetched. 17 * @param imagePrefetcher The current image prefetcher 18 * @param totalCount The total number of images that were prefetched (whether successful or not) 19 * @param skippedCount The total number of images that were skipped 20 */ 21 - (void)imagePrefetcher:(nonnull SDWebImagePrefetcher *)imagePrefetcher didFinishWithTotalCount:(NSUInteger)totalCount skippedCount:(NSUInteger)skippedCount; 22 23 @end
代理提供了两个方法:
1.每次下载完成一个图片,finishedCount 表示对图像进行预取的总数(成功或失败)totalCount 图像将被预取的总数。
2.当所有的图像下载完毕,totalCount 对图像进行预取的总数(无论成功或者失败) skippedCount 跳过的图像的总数,表示下载失败的的总数。
命名block
1 typedef void(^SDWebImagePrefetcherProgressBlock)(NSUInteger noOfFinishedUrls, NSUInteger noOfTotalUrls); 2 typedef void(^SDWebImagePrefetcherCompletionBlock)(NSUInteger noOfFinishedUrls, NSUInteger noOfSkippedUrls);
SDWebImagePrefetcher 属性
1 /** 2 * The web image manager 3 */ 4 @property (strong, nonatomic, readonly, nonnull) SDWebImageManager *manager; 5 6 /** 7 * Maximum number of URLs to prefetch at the same time. Defaults to 3. 8 */ 9 @property (nonatomic, assign) NSUInteger maxConcurrentDownloads; 10 11 /** 12 * SDWebImageOptions for prefetcher. Defaults to SDWebImageLowPriority. 13 */ 14 @property (nonatomic, assign) SDWebImageOptions options; 15 16 /** 17 * Queue options for Prefetcher. Defaults to Main Queue. 18 */ 19 @property (nonatomic, assign, nonnull) dispatch_queue_t prefetcherQueue; 20 21 @property (weak, nonatomic, nullable) id <SDWebImagePrefetcherDelegate> delegate;
SDWebImageManager *manager 网络图像管理器
参考链接:http://www.jianshu.com/p/9b629dbd4d30
以上是关于SDWebImage源码阅读SDWebImagePrefetcher的主要内容,如果未能解决你的问题,请参考以下文章
SDWebImage源码阅读(十五)UIView+WebCacheOperation
SDWebImage源码阅读NSImage+WebCache