DetailViewController.m 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * This file is part of the SDWebImage package.
  3. * (c) Olivier Poitrey <rs@dailymotion.com>
  4. *
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. */
  8. #import "DetailViewController.h"
  9. #import <SDWebImage/UIImageView+WebCache.h>
  10. #import <SDWebImage/FLAnimatedImageView+WebCache.h>
  11. @interface DetailViewController ()
  12. @property (strong, nonatomic) IBOutlet FLAnimatedImageView *imageView;
  13. - (void)configureView;
  14. @end
  15. @implementation DetailViewController
  16. @synthesize imageURL = _imageURL;
  17. @synthesize imageView = _imageView;
  18. #pragma mark - Managing the detail item
  19. - (void)setImageURL:(NSURL *)imageURL
  20. {
  21. if (_imageURL != imageURL)
  22. {
  23. _imageURL = imageURL;
  24. [self configureView];
  25. }
  26. }
  27. - (void)configureView
  28. {
  29. if (self.imageURL) {
  30. __block UIActivityIndicatorView *activityIndicator;
  31. __weak UIImageView *weakImageView = self.imageView;
  32. [self.imageView sd_setImageWithURL:self.imageURL
  33. placeholderImage:nil
  34. options:SDWebImageProgressiveDownload
  35. progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL *targetURL) {
  36. dispatch_async(dispatch_get_main_queue(), ^{
  37. if (!activityIndicator) {
  38. [weakImageView addSubview:activityIndicator = [UIActivityIndicatorView.alloc initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]];
  39. activityIndicator.center = weakImageView.center;
  40. [activityIndicator startAnimating];
  41. }
  42. });
  43. }
  44. completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
  45. [activityIndicator removeFromSuperview];
  46. activityIndicator = nil;
  47. }];
  48. }
  49. }
  50. - (void)viewDidLoad
  51. {
  52. [super viewDidLoad];
  53. [self configureView];
  54. }
  55. - (void)viewDidUnload
  56. {
  57. [super viewDidUnload];
  58. self.imageView = nil;
  59. }
  60. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  61. {
  62. return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
  63. }
  64. @end