SVGAImageView.m 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //
  2. // SVGAImageView.m
  3. // SVGAPlayer
  4. //
  5. // Created by 崔明辉 on 2017/10/17.
  6. // Copyright © 2017年 UED Center. All rights reserved.
  7. //
  8. #import "SVGAImageView.h"
  9. #import "SVGAParser.h"
  10. static SVGAParser *sharedParser;
  11. @implementation SVGAImageView
  12. + (void)load {
  13. sharedParser = [SVGAParser new];
  14. }
  15. - (instancetype)initWithCoder:(NSCoder *)coder
  16. {
  17. self = [super initWithCoder:coder];
  18. if (self) {
  19. _autoPlay = YES;
  20. }
  21. return self;
  22. }
  23. - (void)setImageName:(NSString *)imageName {
  24. _imageName = imageName;
  25. if ([imageName hasPrefix:@"http://"] || [imageName hasPrefix:@"https://"]) {
  26. [sharedParser parseWithURL:[NSURL URLWithString:imageName] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
  27. [self setVideoItem:videoItem];
  28. if (self.autoPlay) {
  29. [self startAnimation];
  30. }
  31. } failureBlock:nil];
  32. }
  33. else {
  34. [sharedParser parseWithNamed:imageName inBundle:nil completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
  35. [self setVideoItem:videoItem];
  36. if (self.autoPlay) {
  37. [self startAnimation];
  38. }
  39. } failureBlock:nil];
  40. }
  41. }
  42. @end