YYFrameImage.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //
  2. // YYFrameImage.h
  3. // YYImage <https://github.com/ibireme/YYImage>
  4. //
  5. // Created by ibireme on 14/12/9.
  6. // Copyright (c) 2015 ibireme.
  7. //
  8. // This source code is licensed under the MIT-style license found in the
  9. // LICENSE file in the root directory of this source tree.
  10. //
  11. #import <UIKit/UIKit.h>
  12. #if __has_include(<YYImage/YYImage.h>)
  13. #import <YYImage/YYAnimatedImageView.h>
  14. #elif __has_include(<YYWebImage/YYImage.h>)
  15. #import <YYWebImage/YYAnimatedImageView.h>
  16. #else
  17. #import "YYAnimatedImageView.h"
  18. #endif
  19. /**
  20. An image to display frame-based animation.
  21. @discussion It is a fully compatible `UIImage` subclass.
  22. It only support system image format such as png and jpeg.
  23. The animation can be played by YYAnimatedImageView.
  24. Sample Code:
  25. NSArray *paths = @[@"/ani/frame1.png", @"/ani/frame2.png", @"/ani/frame3.png"];
  26. NSArray *times = @[@0.1, @0.2, @0.1];
  27. YYFrameImage *image = [YYFrameImage alloc] initWithImagePaths:paths frameDurations:times repeats:YES];
  28. YYAnimatedImageView *imageView = [YYAnimatedImageView alloc] initWithImage:image];
  29. [view addSubView:imageView];
  30. */
  31. @interface YYFrameImage : UIImage <YYAnimatedImage>
  32. /**
  33. Create a frame animated image from files.
  34. @param paths An array of NSString objects, contains the full or
  35. partial path to each image file.
  36. e.g. @[@"/ani/1.png",@"/ani/2.png",@"/ani/3.png"]
  37. @param oneFrameDuration The duration (in seconds) per frame.
  38. @param loopCount The animation loop count, 0 means infinite.
  39. @return An initialized YYFrameImage object, or nil when an error occurs.
  40. */
  41. - (instancetype)initWithImagePaths:(NSArray *)paths oneFrameDuration:(NSTimeInterval)oneFrameDuration loopCount:(NSUInteger)loopCount;
  42. /**
  43. Create a frame animated image from files.
  44. @param paths An array of NSString objects, contains the full or
  45. partial path to each image file.
  46. e.g. @[@"/ani/frame1.png",@"/ani/frame2.png",@"/ani/frame3.png"]
  47. @param frameDurations An array of NSNumber objects, contains the duration (in seconds) per frame.
  48. e.g. @[@0.1, @0.2, @0.3];
  49. @param loopCount The animation loop count, 0 means infinite.
  50. @return An initialized YYFrameImage object, or nil when an error occurs.
  51. */
  52. - (instancetype)initWithImagePaths:(NSArray *)paths frameDurations:(NSArray *)frameDurations loopCount:(NSUInteger)loopCount;
  53. /**
  54. Create a frame animated image from an array of data.
  55. @param dataArray An array of NSData objects.
  56. @param oneFrameDuration The duration (in seconds) per frame.
  57. @param loopCount The animation loop count, 0 means infinite.
  58. @return An initialized YYFrameImage object, or nil when an error occurs.
  59. */
  60. - (instancetype)initWithImageDataArray:(NSArray *)dataArray oneFrameDuration:(NSTimeInterval)oneFrameDuration loopCount:(NSUInteger)loopCount;
  61. /**
  62. Create a frame animated image from an array of data.
  63. @param dataArray An array of NSData objects.
  64. @param frameDurations An array of NSNumber objects, contains the duration (in seconds) per frame.
  65. e.g. @[@0.1, @0.2, @0.3];
  66. @param loopCount The animation loop count, 0 means infinite.
  67. @return An initialized YYFrameImage object, or nil when an error occurs.
  68. */
  69. - (instancetype)initWithImageDataArray:(NSArray *)dataArray frameDurations:(NSArray *)frameDurations loopCount:(NSUInteger)loopCount;
  70. @end