FLAnimatedImageView.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //
  2. // FLAnimatedImageView.h
  3. // Flipboard
  4. //
  5. // Created by Raphael Schaad on 7/8/13.
  6. // Copyright (c) 2013-2015 Flipboard. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. @class FLAnimatedImage;
  10. @protocol FLAnimatedImageViewDebugDelegate;
  11. @protocol FLAnimatedImageViewDelegate
  12. - (void)animatedImageViewWillDrawFrame:(NSUInteger)frameIndex;
  13. @end
  14. //
  15. // An `FLAnimatedImageView` can take an `FLAnimatedImage` and plays it automatically when in view hierarchy and stops when removed.
  16. // The animation can also be controlled with the `UIImageView` methods `-start/stop/isAnimating`.
  17. // It is a fully compatible `UIImageView` subclass and can be used as a drop-in component to work with existing code paths expecting to display a `UIImage`.
  18. // Under the hood it uses a `CADisplayLink` for playback, which can be inspected with `currentFrame` & `currentFrameIndex`.
  19. //
  20. @interface FLAnimatedImageView : UIImageView
  21. // Setting `[UIImageView.image]` to a non-`nil` value clears out existing `animatedImage`.
  22. // And vice versa, setting `animatedImage` will initially populate the `[UIImageView.image]` to its `posterImage` and then start animating and hold `currentFrame`.
  23. @property (nonatomic, strong) FLAnimatedImage *animatedImage;
  24. @property (nonatomic, strong, readonly) UIImage *currentFrame;
  25. @property (nonatomic, assign, readonly) NSUInteger currentFrameIndex;
  26. @property (nonatomic, weak) id<FLAnimatedImageViewDelegate> delegate;
  27. - (void)setCurrentFrameIndex:(NSUInteger)currentFrameIndex;
  28. #if defined(DEBUG) && DEBUG
  29. // Only intended to report internal state for debugging
  30. @property (nonatomic, weak) id<FLAnimatedImageViewDebugDelegate> debug_delegate;
  31. #endif
  32. @end
  33. #if defined(DEBUG) && DEBUG
  34. @protocol FLAnimatedImageViewDebugDelegate <NSObject>
  35. @optional
  36. - (void)debug_animatedImageView:(FLAnimatedImageView *)animatedImageView waitingForFrame:(NSUInteger)index duration:(NSTimeInterval)duration;
  37. @end
  38. #endif