2012-11-16 46 views

回答

1

下載到一個隱藏的UIImageView某處視圖,然後在兩者之間的加載完成時,通過切換,:

[cell.imageView setImageWithURL:[NSURL  
URLWithString:@"http://www.domain.com/path/to/image.jpg"] 
    placeholderImage:[UIImage imageNamed:@"placeholder.png"] 
    completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {... completion code here ...}]; 
5

其實,你並不需要創建任何隱藏UIImageView這樣的伎倆。

您必須做的是將第一個URL(使用較小的圖像)直接下載到您的UIImageView中,然後使用SDWebImageManager在後臺下載較大的版本。完成下載後,只需在圖像視圖中設置下載的圖像。

這裏是你如何能做到這一點:

// First let the smaller image download naturally 
[self.imageView setImageWithURL:self.imageURL]; 

// Slowly download the larger version of the image 
SDWebImageManager *manager = [SDWebImageManager sharedManager]; 
[manager downloadWithURL:self.currentPhoto.largeImageURL options:SDWebImageLowPriority progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) { 
    if (image) { 
     [self.imageView setImage:image]; 
    } 
}]; 

注意我如何使用SDWebImageLowPriority選項。這樣,圖像(應該比第一個圖像自然大)將以低優先級下載,並且不應取消第一次下載。

+0

我可以使用的tableview細胞圖像同樣的伎倆? –

+0

我不明白爲什麼不。只要確保在單元格出界後取消請求,那麼您以後不會重複使用該單元格 –

2

現在已經晚了,但我解決了我的問題,下面的代碼

UIImageView * hiddenImageView = [[UIImageView alloc] init]; 

[hiddenImageView sd_setImageWithURL:thumbUrl completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { 

    if (image) { 

     mImageView.image = image; 
    } 

    if (originalUrl != nil) { 

     [mImageView sd_setImageWithURL:originalUrl placeholderImage:image completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL){ 

      if (image) { 

       mImageView.image = image; // optional 
      } 

     }]; 

    } 
}]; 
相關問題