【问题标题】:iOS SDWebImage Cross Fade Effect UITableViewCelliOS SDWebImage 交叉淡入淡出效果 UITableViewCell
【发布时间】:2013-07-29 12:42:40
【问题描述】:

这就是我成功使用 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控制器,当它触及底部时它正在加载更多条目,它在新的条目块之前刷新所有单元格已加载,我该如何防止这种行为?

【问题讨论】:

    标签: ios uitableview sdwebimage


    【解决方案1】:

    看起来您在另一个文件中使用 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
                            }];
    

    希望这会有所帮助!

    【讨论】:

      【解决方案2】:

      您可以使用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
                      }];
      

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

      【讨论】:

        【解决方案3】:

        请参考接口定义:

        - (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
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-04-19
          • 2016-05-12
          • 1970-01-01
          相关资源
          最近更新 更多