DetailViewController.m
1.8 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
//
// DetailViewController.m
// SDWebImage Demo
//
// Created by Olivier Poitrey on 09/05/12.
// Copyright (c) 2012 Dailymotion. All rights reserved.
//
#import "DetailViewController.h"
#import <SDWebImage/UIImageView+WebCache.h>
@interface DetailViewController ()
- (void)configureView;
@end
@implementation DetailViewController
@synthesize imageURL = _imageURL;
@synthesize imageView = _imageView;
#pragma mark - Managing the detail item
- (void)setImageURL:(NSURL *)imageURL
{
if (_imageURL != imageURL)
{
_imageURL = imageURL;
[self configureView];
}
}
- (void)configureView
{
if (self.imageURL)
{
__block UIActivityIndicatorView *activityIndicator;
__weak UIImageView *weakImageView = self.imageView;
[self.imageView setImageWithURL:self.imageURL placeholderImage:nil options:SDWebImageProgressiveDownload progress:^(NSUInteger receivedSize, long long expectedSize)
{
if (!activityIndicator)
{
[weakImageView addSubview:activityIndicator = [UIActivityIndicatorView.alloc initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]];
activityIndicator.center = weakImageView.center;
[activityIndicator startAnimating];
}
}
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType)
{
[activityIndicator removeFromSuperview];
activityIndicator = nil;
}];
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self configureView];
}
- (void)viewDidUnload
{
[super viewDidUnload];
self.imageView = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end