在SDWebImage中显示活动指示器 [英] Show activity indicator in SDWebImage

查看:97
本文介绍了在SDWebImage中显示活动指示器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SDWebView图像,并且希望从远程获取图像时将活动指示器"显示为占位符.

I'm using SDWebView image and i want to show an Activity Indicator as placeholder, while fetching the image from remote.

我在这里尝试了Malek的答案如何在SDWebImage中显示活动指示器,但似乎

I tried Malek's answer here How to show an activity indicator in SDWebImage, but it seems that

UIImage *cachedImage = [manager imageWithURL:url];

已弃用.

有没有人使用此库可以告诉我如何在加载图像时插入活动指示器?

Is there anyone using this library that could tell me how can i insert an Activity Indicator while loading the image?

编辑

按照迈克尔·弗雷德里克(Michael Frederick)的指示,我最终得到了这段代码,并且一切正常.

Following the indications of Michael Frederick, i ended up with this code and everything's working fine.

UIActivityIndicatorView *activityIndicator = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite] autorelease];
activityIndicator.hidesWhenStopped = YES;
activityIndicator.hidden = NO;
[activityIndicator startAnimating];
activityIndicator.center = CGPointMake(self.tipImage.frame.size.width /2, self.tipImage.frame.size.height/2);
[imageView setImageWithURL:[NSURL URLWithString:imageString]
          placeholderImage:nil options:SDWebImageProgressiveDownload
                   success:^(UIImage *image) { [activityIndicator stopAnimating];[activityIndicator removeFromSuperview]; }
                   failure:^(NSError *error) {  [activityIndicator stopAnimating];[activityIndicator removeFromSuperview]; }];

[imageView addSubview:activityIndicator];

推荐答案

此fork 支持为此功能.看看差异.

This fork has support for this functionality. Take a look at the diff.

但是,通常来说,您无需使用该fork就可以轻松地做到这一点:

But, in general, you can do it rather easily without using that fork:

__block UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:activityStyle];
activityIndicator.center = imageView.center;
activityIndicator.hidesWhenStopped = YES;
[imageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
               placeholderImage:[UIImage imageNamed:@"placeholder.png"]
                        success:^(UIImage *image) { [activityIndicator removeFromSuperview]; }
                        failure:^(NSError *error) { [activityIndicator removeFromSuperview]; }];

[imageView addSubview:activityIndicator];
[activityIndicator startAnimating];

这篇关于在SDWebImage中显示活动指示器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆