我使用SDWebImage异步地在UIImageView中下载和缓存图像,但我面临一些问题。
在我的项目中,我创建了一个引脚标记,其中有一个对话框,其中包含UIImageView。
我面临的问题是,在下载完成后,来自url的图片并没有替换位置持有者的图像。第一次点击别针标志将始终显示的地方持有人形象。
来自url的图像只有在我第二次点击引脚标记后才会显示。
我想显示图片从url在第一次点击,我应该做什么?
这是我的密码
-(UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker{
PlaceData *currentMarker = [self findDataByMarker:marker];
UIView *dialogView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 261, 95)];
// Create background image
UIImageView *dialogBackground = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"MapDialog.png"]];
[dialogView addSubview:dialogBackground];
UIImageView * thumbnail = [[UIImageView alloc] init];
[thumbnail sd_setImageWithURL:[NSURL URLWithString:currentMarker.thumbnail] placeholderImage:[UIImage imageNamed:@"placeholder.png"] options:SDWebImageRefreshCached];
NSLog(@"URL %@", currentMarker.thumbnail);
NSLog(@"thumbnail %@",thumbnail);
CGRect tmpFrame = thumbnail.frame;
tmpFrame.origin.x = 15;
tmpFrame.origin.y = 14;
tmpFrame.size.width = 55;
tmpFrame.size.height = 55;
thumbnail.frame = tmpFrame;
thumbnail.contentMode = UIViewContentModeScaleToFill;
[dialogView addSubview:thumbnail];
return dialogView;
PS。请帮我解决这个问题,对不起我的英语。
发布于 2015-09-15 10:48:41
请试一试这段代码
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[thumbnail sd_setImageWithURL:[NSURL URLWithString:currentMarker.thumbnail] placeholderImage:[UIImage imageNamed:@"placeholder.png"] options:SDWebImageRefreshCached];
});
发布于 2020-02-27 16:33:06
.retryFailed,.refreshCached帮我解决了这个问题。
imageView.sd_setImage(with: picnicThumbnail, maxImageSize: 100000, placeholderImage: placeholderImage, options: [.retryFailed, .refreshCached], completion : nil)
https://stackoverflow.com/questions/32593213
复制