YYFrameImage.h 3.7 KB

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