MWPhotoProtocol.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //
  2. // MWPhotoProtocol.h
  3. // MWPhotoBrowser
  4. //
  5. // Created by Michael Waterfall on 02/01/2012.
  6. // Copyright (c) 2012 __MyCompanyName__. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. // Notifications
  10. #define MWPHOTO_LOADING_DID_END_NOTIFICATION @"MWPHOTO_LOADING_DID_END_NOTIFICATION"
  11. #define MWPHOTO_PROGRESS_NOTIFICATION @"MWPHOTO_PROGRESS_NOTIFICATION"
  12. // If you wish to use your own data models for photo then they must conform
  13. // to this protocol. See instructions for details on each method.
  14. // Otherwise you can use the MWPhoto object or subclass it yourself to
  15. // store more information per photo.
  16. //
  17. // You can see the MWPhoto class for an example implementation of this protocol
  18. //
  19. @protocol MWPhoto <NSObject>
  20. @required
  21. // Return underlying UIImage to be displayed
  22. // Return nil if the image is not immediately available (loaded into memory, preferably
  23. // already decompressed) and needs to be loaded from a source (cache, file, web, etc)
  24. // IMPORTANT: You should *NOT* use this method to initiate
  25. // fetching of images from any external of source. That should be handled
  26. // in -loadUnderlyingImageAndNotify: which may be called by the photo browser if this
  27. // methods returns nil.
  28. @property (nonatomic, strong) UIImage *underlyingImage;
  29. // Called when the browser has determined the underlying images is not
  30. // already loaded into memory but needs it.
  31. - (void)loadUnderlyingImageAndNotify;
  32. // Fetch the image data from a source and notify when complete.
  33. // You must load the image asyncronously (and decompress it for better performance).
  34. // It is recommended that you use SDWebImageDecoder to perform the decompression.
  35. // See MWPhoto object for an example implementation.
  36. // When the underlying UIImage is loaded (or failed to load) you should post the following
  37. // notification:
  38. // [[NSNotificationCenter defaultCenter] postNotificationName:MWPHOTO_LOADING_DID_END_NOTIFICATION
  39. // object:self];
  40. - (void)performLoadUnderlyingImageAndNotify;
  41. // This is called when the photo browser has determined the photo data
  42. // is no longer needed or there are low memory conditions
  43. // You should release any underlying (possibly large and decompressed) image data
  44. // as long as the image can be re-loaded (from cache, file, or URL)
  45. - (void)unloadUnderlyingImage;
  46. @optional
  47. // If photo is empty, in which case, don't show loading error icons
  48. @property (nonatomic) BOOL emptyImage;
  49. // Video
  50. @property (nonatomic) BOOL isVideo;
  51. - (void)getVideoURL:(void (^)(NSURL *url))completion;
  52. // Return a caption string to be displayed over the image
  53. // Return nil to display no caption
  54. - (NSString *)caption;
  55. // Cancel any background loading of image data
  56. - (void)cancelAnyLoading;
  57. @end