我使用SDWebImage代码,从网上下载一张图片。GitHub SDWebImage是在Xcode 8和Swift 3中这样做的。
我想调整它的大小,一旦它被下载,但我不能有图像大小,直到我下载的图像。(按比例调整大小)
所以,我的问题是,是否有一种方法,有一个完成块,以执行一些代码时,图像已完成下载?我似乎找不到关于完成下载的github项目信息。
谢谢!
发布于 2016-12-30 17:05:38
我找到了!把它寄出去,以防别人需要它。
我用这个从网上加载
imgView.sd_setImage(with: URL(string: news.imageURL))但是对于负载和完成块,我需要这样做:
imgView.sd_setImage(with: URL(string: news.imageURL)) { (image, error, cache, url) in
// Your code inside completion block
}发布于 2016-12-30 16:11:17
下面是一个SDWebImage示例文件中的一些代码,您可以在这里找到更多的示例:https://github.com/rs/SDWebImage/tree/master/Examples
迅捷版:
imageView.sd_setImageWithURL(NSURL(string: urlString), completed: {
(image, error, cacheType, url) in
// your code
})目标-C版:
- (void)configureView
{
if (self.imageURL) {
__block UIActivityIndicatorView *activityIndicator;
__weak UIImageView *weakImageView = self.imageView;
[self.imageView sd_setImageWithURL:self.imageURL
placeholderImage:nil
options:SDWebImageProgressiveDownload
progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL *targetURL) {
if (!activityIndicator) {
[weakImageView addSubview:activityIndicator = [UIActivityIndicatorView.alloc initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]];
activityIndicator.center = weakImageView.center;
[activityIndicator startAnimating];
}
}
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
[activityIndicator removeFromSuperview];
activityIndicator = nil;
}];
}
}希望这能有所帮助。
https://stackoverflow.com/questions/41399091
复制相似问题