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秒內實現加載圖像?