2012-09-08 142 views
0

我可以使用SDWebImage加載一個帶有URL的小尺寸圖像,以顯示在UIImageView上。但我不知道如何加載一個更大的圖像與另一個URL來顯示在同一個UIImageView後,我已經加載了較小的大小的圖像。如何在UIImageView中加載並顯示小尺寸圖像後加載大尺寸圖像?

[aImageView setImageWithURL:fristUrl placeholderImage:[UIImage imageNamed:@"placeholder.png"] success:^(UIImage *image) { 
    [aImageView setImageWithURL:secondUrl placeholderImage:image success:^(UIImage *image) { 
     ; 
    } failure:^(NSError *error) { 
     NSLog(@"error105size:%@", [error description]); 
    }]; 
} failure:^(NSError *error) { 
    NSLog(@"error50size:%@", [error description]); 
}]; 

我已經使用了上面的代碼,但它崩潰了。 希望你的回答。

回答

0

其實,你並不需要創建任何隱藏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
UIButton *btn = [[UIButton alloc] init]; 
[btn sd_setImageWithURL:[NSURL URLWithString:obj.thumbnail_pic] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"photoDefault.png"] options:SDWebImageProgressiveDownload completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { 
    NSLog(@"img samll download ok:%@",obj.thumbnail_pic); 
    if (image) { 
     [btn sd_setImageWithURL: [NSURL URLWithString:[ctl getBigImg:obj.thumbnail_pic]] forState:UIControlStateNormal 
       placeholderImage:image]; 
    } 
}];