YYFrameImage.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. NS_ASSUME_NONNULL_BEGIN
  20. /**
  21. An image to display frame-based animation.
  22. @discussion It is a fully compatible `UIImage` subclass.
  23. It only support system image format such as png and jpeg.
  24. The animation can be played by YYAnimatedImageView.
  25. Sample Code:
  26. NSArray *paths = @[@"/ani/frame1.png", @"/ani/frame2.png", @"/ani/frame3.png"];
  27. NSArray *times = @[@0.1, @0.2, @0.1];
  28. YYFrameImage *image = [YYFrameImage alloc] initWithImagePaths:paths frameDurations:times repeats:YES];
  29. YYAnimatedImageView *imageView = [YYAnimatedImageView alloc] initWithImage:image];
  30. [view addSubView:imageView];
  31. */
  32. @interface YYFrameImage : UIImage <YYAnimatedImage>
  33. /**
  34. Create a frame animated image from files.
  35. @param paths An array of NSString objects, contains the full or
  36. partial path to each image file.
  37. e.g. @[@"/ani/1.png",@"/ani/2.png",@"/ani/3.png"]
  38. @param oneFrameDuration The duration (in seconds) per frame.
  39. @param loopCount The animation loop count, 0 means infinite.
  40. @return An initialized YYFrameImage object, or nil when an error occurs.
  41. */
  42. - (nullable instancetype)initWithImagePaths:(NSArray<NSString *> *)paths
  43. oneFrameDuration:(NSTimeInterval)oneFrameDuration
  44. loopCount:(NSUInteger)loopCount;
  45. /**
  46. Create a frame animated image from files.
  47. @param paths An array of NSString objects, contains the full or
  48. partial path to each image file.
  49. e.g. @[@"/ani/frame1.png",@"/ani/frame2.png",@"/ani/frame3.png"]
  50. @param frameDurations An array of NSNumber objects, contains the duration (in seconds) per frame.
  51. e.g. @[@0.1, @0.2, @0.3];
  52. @param loopCount The animation loop count, 0 means infinite.
  53. @return An initialized YYFrameImage object, or nil when an error occurs.
  54. */
  55. - (nullable instancetype)initWithImagePaths:(NSArray<NSString *> *)paths
  56. frameDurations:(NSArray<NSNumber *> *)frameDurations
  57. loopCount:(NSUInteger)loopCount;
  58. /**
  59. Create a frame animated image from an array of data.
  60. @param dataArray An array of NSData objects.
  61. @param oneFrameDuration The duration (in seconds) per frame.
  62. @param loopCount The animation loop count, 0 means infinite.
  63. @return An initialized YYFrameImage object, or nil when an error occurs.
  64. */
  65. - (nullable instancetype)initWithImageDataArray:(NSArray<NSData *> *)dataArray
  66. oneFrameDuration:(NSTimeInterval)oneFrameDuration
  67. loopCount:(NSUInteger)loopCount;
  68. /**
  69. Create a frame animated image from an array of data.
  70. @param dataArray An array of NSData objects.
  71. @param frameDurations An array of NSNumber objects, contains the duration (in seconds) per frame.
  72. e.g. @[@0.1, @0.2, @0.3];
  73. @param loopCount The animation loop count, 0 means infinite.
  74. @return An initialized YYFrameImage object, or nil when an error occurs.
  75. */
  76. - (nullable instancetype)initWithImageDataArray:(NSArray<NSData *> *)dataArray
  77. frameDurations:(NSArray *)frameDurations
  78. loopCount:(NSUInteger)loopCount;
  79. @end
  80. NS_ASSUME_NONNULL_END