DetailViewController.m 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //
  2. // DetailViewController.m
  3. // SDWebImage Demo
  4. //
  5. // Created by Olivier Poitrey on 09/05/12.
  6. // Copyright (c) 2012 Dailymotion. All rights reserved.
  7. //
  8. #import "DetailViewController.h"
  9. #import <SDWebImage/UIImageView+WebCache.h>
  10. @interface DetailViewController ()
  11. - (void)configureView;
  12. @end
  13. @implementation DetailViewController
  14. @synthesize imageURL = _imageURL;
  15. @synthesize imageView = _imageView;
  16. #pragma mark - Managing the detail item
  17. - (void)setImageURL:(NSURL *)imageURL
  18. {
  19. if (_imageURL != imageURL)
  20. {
  21. _imageURL = imageURL;
  22. [self configureView];
  23. }
  24. }
  25. - (void)configureView
  26. {
  27. if (self.imageURL) {
  28. __block UIActivityIndicatorView *activityIndicator;
  29. __weak UIImageView *weakImageView = self.imageView;
  30. [self.imageView sd_setImageWithURL:self.imageURL
  31. placeholderImage:nil
  32. options:SDWebImageProgressiveDownload
  33. progress:^(NSInteger receivedSize, NSInteger expectedSize) {
  34. if (!activityIndicator) {
  35. [weakImageView addSubview:activityIndicator = [UIActivityIndicatorView.alloc initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]];
  36. activityIndicator.center = weakImageView.center;
  37. [activityIndicator startAnimating];
  38. }
  39. }
  40. completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
  41. [activityIndicator removeFromSuperview];
  42. activityIndicator = nil;
  43. }];
  44. }
  45. }
  46. - (void)viewDidLoad
  47. {
  48. [super viewDidLoad];
  49. [self configureView];
  50. }
  51. - (void)viewDidUnload
  52. {
  53. [super viewDidUnload];
  54. self.imageView = nil;
  55. }
  56. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  57. {
  58. return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
  59. }
  60. @end