...
|
...
|
@@ -7,55 +7,66 @@ |
|
|
*/
|
|
|
|
|
|
#import "DetailViewController.h"
|
|
|
#import <SDWebImage/UIImageView+WebCache.h>
|
|
|
#import <SDWebImage/FLAnimatedImageView.h>
|
|
|
#import <SDWebImage/FLAnimatedImageView+WebCache.h>
|
|
|
|
|
|
@interface DetailViewController ()
|
|
|
|
|
|
@property (strong, nonatomic) IBOutlet FLAnimatedImageView *imageView;
|
|
|
|
|
|
- (void)configureView;
|
|
|
@property (strong, nonatomic) UIActivityIndicatorView *activityIndicator;
|
|
|
@property (strong, nonatomic) UIProgressView *progressView;
|
|
|
|
|
|
@end
|
|
|
|
|
|
@implementation DetailViewController
|
|
|
|
|
|
@synthesize imageURL = _imageURL;
|
|
|
@synthesize imageView = _imageView;
|
|
|
|
|
|
#pragma mark - Managing the detail item
|
|
|
- (UIActivityIndicatorView *)activityIndicator
|
|
|
{
|
|
|
if (!_activityIndicator) {
|
|
|
_activityIndicator = [UIActivityIndicatorView.alloc initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
|
|
|
_activityIndicator.center = self.imageView.center;
|
|
|
_activityIndicator.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
|
|
|
[self.imageView addSubview:_activityIndicator];
|
|
|
|
|
|
}
|
|
|
return _activityIndicator;
|
|
|
}
|
|
|
|
|
|
- (void)setImageURL:(NSURL *)imageURL
|
|
|
- (UIProgressView *)progressView
|
|
|
{
|
|
|
if (_imageURL != imageURL)
|
|
|
{
|
|
|
_imageURL = imageURL;
|
|
|
[self configureView];
|
|
|
if (!_progressView) {
|
|
|
_progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
|
|
|
_progressView.frame = CGRectMake(0, CGRectGetMaxY(self.navigationController.navigationBar.frame), CGRectGetWidth(self.view.frame), 2.0);
|
|
|
_progressView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
|
|
|
[self.view addSubview:_progressView];
|
|
|
}
|
|
|
return _progressView;
|
|
|
}
|
|
|
|
|
|
- (void)configureView
|
|
|
{
|
|
|
if (self.imageURL) {
|
|
|
__block UIActivityIndicatorView *activityIndicator;
|
|
|
__weak UIImageView *weakImageView = self.imageView;
|
|
|
[self.imageView sd_setImageWithURL:self.imageURL
|
|
|
placeholderImage:nil
|
|
|
options:SDWebImageProgressiveDownload
|
|
|
progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL *targetURL) {
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
if (!activityIndicator) {
|
|
|
[weakImageView addSubview:activityIndicator = [UIActivityIndicatorView.alloc initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]];
|
|
|
activityIndicator.center = weakImageView.center;
|
|
|
[activityIndicator startAnimating];
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
|
|
[activityIndicator removeFromSuperview];
|
|
|
activityIndicator = nil;
|
|
|
}];
|
|
|
}
|
|
|
self.activityIndicator.hidden = NO;
|
|
|
[self.activityIndicator startAnimating];
|
|
|
|
|
|
__weak typeof(self) weakSelf = self;
|
|
|
[self.imageView sd_setImageWithURL:self.imageURL
|
|
|
placeholderImage:nil
|
|
|
options:SDWebImageProgressiveDownload
|
|
|
progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL *targetURL) {
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
float progress = 0;
|
|
|
if (expectedSize != 0) {
|
|
|
progress = (float)receivedSize / (float)expectedSize;
|
|
|
}
|
|
|
weakSelf.progressView.hidden = NO;
|
|
|
[weakSelf.progressView setProgress:progress animated:YES];
|
|
|
});
|
|
|
}
|
|
|
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
|
|
weakSelf.progressView.hidden = YES;
|
|
|
[weakSelf.activityIndicator stopAnimating];
|
|
|
weakSelf.activityIndicator.hidden = YES;
|
|
|
}];
|
|
|
}
|
|
|
|
|
|
- (void)viewDidLoad
|
...
|
...
|
@@ -64,12 +75,6 @@ |
|
|
[self configureView];
|
|
|
}
|
|
|
|
|
|
- (void)viewDidUnload
|
|
|
{
|
|
|
[super viewDidUnload];
|
|
|
self.imageView = nil;
|
|
|
}
|
|
|
|
|
|
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
|
|
|
{
|
|
|
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
|
...
|
...
|
|