objective-c – 在SDWebImage中显示活动指示器

我使用SDWebView图像,我想显示一个活动指示符作为占位符,而从远程获取图像。

我试过Malek的答案这里How to show an activity indicator in SDWebImage,但似乎

UIImage *cachedImage = [manager imageWithURL:url];

已弃用。

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

编辑

按照迈克尔·弗雷德里克的迹象,我结束了这个代码,一切工作正常。

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];
This fork支持此功能。看看the diff

但是,一般来说,你可以做到相当容易,而不使用该叉:

__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];
http://stackoverflow.com/questions/11262204/show-activity-indicator-in-sdwebimage

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:objective-c – 在SDWebImage中显示活动指示器