4

这就是我成功使用 SDWebImageManager 下载图像的方式:

- (void) downloadThumbnails:(NSURL *) finalUrl
{
    SDWebImageManager *manager = [SDWebImageManager sharedManager];
    [manager downloadWithURL:finalUrl
                     options:0
                    progress:nil
                   completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) {

                       if (image)
                       {
                           self.thumbnailURL = [finalUrl absoluteString];
                        }
                   }];
}

- (UIImage*)thumbnail {

    if (!self.thumbnailURL) return nil;
    return [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:self.thumbnailURL];
}

如何修改以具有交叉淡入淡出效果?交叉淡入淡出效果是一种使图像显示过渡缓慢的效果,就像 TechCrunch iOS 应用程序一样。谢谢!

更新:如果我可以做任何其他事情来在 uitableview 单元格中产生交叉淡入淡出效果(SDWebImage 除外),那么您可以将其写在答案中。

更新:我上次更新后收到的答案很少,我能够部分解决问题。在下面的答案中使用 transitionWithView ,它正在工作并以我想要的方式交叉淡入淡出,但是因为我使用的是 tableivew 控制器,当它触及底部时它正在加载更多条目,它会在新的条目块之前刷新所有单元格一次已加载,我该如何防止这种行为?

4

3 回答 3

4

看起来您在另一个文件中使用 SDWebImageManager,该文件不一定是 UITableViewController 类。如果它在不同的类中,您可以直接使用 transitionWithView 但不能直接使用 SDWebImageManager。

但是在您使用 cellForRowAtIndexPath 并将图像与 UITableViewCell 的 imageView 链接的表视图控制器类中,您可以使用如下所示的 transitionView:

[UIView transitionWithView:cell.(Your Image View)
                          duration:0.5
                           options:UIViewAnimationOptionTransitionCrossDissolve
                        animations:^{

                            cell.(Your ImageView).image = [(how ever you are calling it)];


                        } completion:^(BOOL finished) {
                            //  Optionally you can do anything after the completion
                        }];

希望这可以帮助!

于 2013-08-04T20:56:30.360 回答
1

您可以使用UIView transitionWithView:duration:options:animations:completion:方法将图像视图从旧图像交叉溶解到新图像,如下所示:

[UIView transitionWithView:imageView
                  duration:0.4
                   options:UIViewAnimationOptionTransitionCrossDissolve
                animations:^{
                    //  Set the new image
                    //  Since its done in the animation block, the change will be animated
                    imageView.image = newImage;
                } completion:^(BOOL finished) {
                    //  Do whatever when the animation is finished
                }];

只需在您completed通常将图像设置为的块中使用此代码imageView

于 2013-08-01T15:14:08.967 回答
-1

请参考接口定义:

- (id<SDWebImageOperation>)downloadWithURL:(NSURL *)url
                                   options:(SDWebImageOptions)options
                                  progress:(SDWebImageDownloaderProgressBlock)progressBlock
                                 completed:(SDWebImageCompletedWithFinishedBlock)completedBlock;

SDImageOptions 有几个价值,我认为这是您所期望的:

/**
 * This flag enables progressive download, the image is displayed progressively during download as a browser would do.
 * By default, the image is only displayed once completely downloaded.
 */
SDWebImageProgressiveDownload = 1 << 3
于 2013-08-01T14:56:36.413 回答