YYFrameImage.h 3.3 KB

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