0
我有一个代码来显示来自远程URL的图像。如何显示UIImageView的加载图像
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSData *imageData = nil;
imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:image]];
if (imageData){
dispatch_async(dispatch_get_main_queue(), ^{
// UIKit, which includes UIImage warns about not being thread safe
// So we switch to main thread to instantiate image
UIImage *image1 = [UIImage imageWithData:imageData];
self.imageLabel.image = image1;
});
}
});
但下载图像需要2秒。我试图把动画加载图像到UIImageView,但没有奏效。我如何在2秒内实现加载图像?