DetailViewController.m
3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* This file is part of the SDWebImage package.
* (c) Olivier Poitrey <rs@dailymotion.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
#import "DetailViewController.h"
#import <SDWebImage/FLAnimatedImageView.h>
#import <SDWebImage/FLAnimatedImageView+WebCache.h>
@interface DetailViewController ()
@property (strong, nonatomic) IBOutlet FLAnimatedImageView *imageView;
@property (strong, nonatomic) UIActivityIndicatorView *activityIndicator;
@property (strong, nonatomic) UIProgressView *progressView;
@end
@implementation DetailViewController
- (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;
}
- (UIProgressView *)progressView
{
if (!_progressView) {
_progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
[self.view addSubview:_progressView];
}
return _progressView;
}
- (void)configureView
{
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
{
[super viewDidLoad];
[self configureView];
}
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
self.progressView.frame = CGRectMake(0, self.topLayoutGuide.length, CGRectGetWidth(self.view.bounds), 2.0);
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end