理解SDWebImage下载器
Comprehending SDWebImage downloader
文档不适合我。有人可以给我示例代码或实例化 SDWebImage 下载器和使用 downloadImageWithURL 方法的示例吗?
我为此创建了一个 class,但我是这样使用它的:
- (void)setImageURL:(NSURL *)imageURL {
_imageURL = imageURL;
self.image = nil;
[self.layer removeAllAnimations];
if (!imageURL) {
self.image = self.placeHolderImage;
return;
}
__weak SDImageView *weakself = self;
self.progressView.hidden = NO;
SDWebImageDownloaderProgressBlock progressBlock =
^(NSInteger receivedSize, NSInteger expectedSize) {
if (expectedSize > 0) {
float progress = receivedSize / (float)expectedSize;
weakself.progressView.progress = MAX(MIN(1, progress), 0);
}
};
SDWebImageCompletionWithFinishedBlock successBlock =
^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
if (!image) image = self.placeHolderImage;
weakself.imageOperation = nil;
weakself.progressView.hidden = YES;
weakself.progressView.progress = 0.f;
if (cacheType == SDImageCacheTypeNone && !error) {
[UIView transitionWithView:self
duration:1.f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
weakself.image = image;
} completion:nil];
} else {
weakself.image = image;
}
};
SDWebImageManager *manager = [SDWebImageManager sharedManager];
self.imageOperation = [manager downloadImageWithURL:imageURL
options:SDWebImageRetryFailed
progress:progressBlock
completed:successBlock];
}
你想做什么?给我们更多的细节。
计算器溢出:
文档不适合我。有人可以给我示例代码或实例化 SDWebImage 下载器和使用 downloadImageWithURL 方法的示例吗?
我为此创建了一个 class,但我是这样使用它的:
- (void)setImageURL:(NSURL *)imageURL {
_imageURL = imageURL;
self.image = nil;
[self.layer removeAllAnimations];
if (!imageURL) {
self.image = self.placeHolderImage;
return;
}
__weak SDImageView *weakself = self;
self.progressView.hidden = NO;
SDWebImageDownloaderProgressBlock progressBlock =
^(NSInteger receivedSize, NSInteger expectedSize) {
if (expectedSize > 0) {
float progress = receivedSize / (float)expectedSize;
weakself.progressView.progress = MAX(MIN(1, progress), 0);
}
};
SDWebImageCompletionWithFinishedBlock successBlock =
^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
if (!image) image = self.placeHolderImage;
weakself.imageOperation = nil;
weakself.progressView.hidden = YES;
weakself.progressView.progress = 0.f;
if (cacheType == SDImageCacheTypeNone && !error) {
[UIView transitionWithView:self
duration:1.f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
weakself.image = image;
} completion:nil];
} else {
weakself.image = image;
}
};
SDWebImageManager *manager = [SDWebImageManager sharedManager];
self.imageOperation = [manager downloadImageWithURL:imageURL
options:SDWebImageRetryFailed
progress:progressBlock
completed:successBlock];
}
你想做什么?给我们更多的细节。
计算器溢出: