2014-07-23 60 views
0

目前我的圖片只是彈出到視圖中。我希望他們淡入如何淡入SDImageCache圖片

我已經試過了,沒有運氣:

SDImageCache *imageCache = [SDImageCache sharedImageCache]; 
     [imageCache queryDiskCacheForKey:encodedString done:^(UIImage *image, SDImageCacheType cacheType) { 

      if (image){ 
       cell.thumbnailImageView.image = image; 
      }else{ 
       [cell.thumbnailImageView setImageWithURL:[NSURL URLWithString:encodedString] placeholderImage:myImage completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) { 

        [imageCache storeImage:image forKey:encodedString]; 

       }]; 

       UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; 
       imageView.alpha = 0; 

       [UIView animateWithDuration:5.0 animations:^{ 
        imageView.alpha = 1.0; 
       }]; 
      } 
     }]; 

回答

0

你else塊應該看起來像如下:

[[SDWebImageManager sharedManager] downloadWithURL:[NSURL URLWithString:encodedString] 
            options:0 
            progress:nil 
            completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) { 

        [imageCache storeImage:image forKey:encodedString]; 
        UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; 
        imageView.alpha = 0; 

        [UIView animateWithDuration:5.0 animations:^{ 
         imageView.alpha = 1.0; 
        }]; 
       }]; 
+0

這不起作用與上次propperly我得到的錯誤'}]'所以我代替吧'});'現在的圖像正在用錯誤的圖像 – maxisme

+0

我已經取代!更新了我的代碼中刪除一個「(」 –

+0

還是慢騰騰的圖像 – maxisme

0

嘗試下面的代碼。

__weak typeof(UIImageView)* weakimgView = imgView;

[imgView setImageWithURL:[NSURL URLWithString:_photo.url placeholderImage:[UIImage imageNamed:@"photoIcon"] options:SDWebImageRetryFailed completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) { 

      [weakimgView setAlpha:0.4]; 

      [UIView beginAnimations:nil context:nil]; 
      [UIView setAnimationDuration:0.5]; 

      weakimgView.image = image; 
      [weakimgView setAlpha:1.0]; 


      [UIView commitAnimations]; 


    }]; 

希望這會對你有所幫助。快樂編碼:)