YOUPAILZCarDressHeaderView.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //
  2. // YOUPAILZCarDressHeaderView.m
  3. // VQU
  4. //
  5. // Created by CY on 2021/8/23.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAILZCarDressHeaderView.h"
  9. #import <SVGAPlayer.h>
  10. #import <SVGAParser.h>
  11. @interface YOUPAILZCarDressHeaderView ()<SVGAPlayerDelegate>
  12. @property (nonatomic, strong) SVGAPlayer *youpaipsvgaPlayer;
  13. @property (nonatomic, strong) SVGAParser *youpaipparser;
  14. @end
  15. @implementation YOUPAILZCarDressHeaderView
  16. - (instancetype)initWithFrame:(CGRect)frame{
  17. if (self = [super initWithFrame:frame]) {
  18. [self youpaifinitUI];
  19. }
  20. return self;
  21. }
  22. - (void)youpaifinitUI{
  23. UIImageView *bgImgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"vqu_images_ic_profile_dress_bg"]];
  24. [self addSubview:bgImgV];
  25. [bgImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  26. make.left.top.bottom.right.offset(0.0f);
  27. }];
  28. bgImgV.userInteractionEnabled = YES;
  29. self.youpaipsvgaPlayer = [[SVGAPlayer alloc] init];
  30. self.youpaipsvgaPlayer.contentMode = UIViewContentModeScaleAspectFit;
  31. self.youpaipsvgaPlayer.delegate = self;
  32. [self addSubview:self.youpaipsvgaPlayer];
  33. [self.youpaipsvgaPlayer mas_makeConstraints:^(MASConstraintMaker *make) {
  34. make.centerX.equalTo(self);
  35. make.centerY.equalTo(self);
  36. make.size.mas_offset(CGSizeMake(135.0f, 135.0f));
  37. }];
  38. self.youpaipsvgaPlayer.hidden = YES;
  39. self.youpaipsvgaPlayer.loops = 0;
  40. self.youpaipsvgaPlayer.clearsAfterStop = true;
  41. self.youpaipparser = [[SVGAParser alloc] init];
  42. }
  43. - (void)youpaifreloadWithModel:(YOUPAILZDressModel *)model{
  44. [self.youpaipsvgaPlayer stopAnimation];
  45. if (![model.youpaippreview_img isEqualToString:@""]) {
  46. self.youpaipsvgaPlayer.hidden = NO;
  47. }
  48. NSString* svgaName = [[model.youpaippreview_img componentsSeparatedByString:@"/"] lastObject];
  49. NSString* svgaCanchesPath= [[NSString alloc]initWithFormat:@"%@/%@/%@",CachesPath,@"SVGA",svgaName];
  50. [self.youpaipsvgaPlayer stopAnimation];
  51. if (![LCTools giftSVGAWithSvgaUrlStr:model.youpaippreview_img]){
  52. NSString* urlStr = [NSString stringWithFormat:@"%@/%@",[LCSaveData getImageUrl]?[LCSaveData getImageUrl]:BaseImgUrl,model.youpaippreview_img];
  53. @weakify(self);
  54. [self.youpaipparser parseWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
  55. @strongify(self);
  56. if (videoItem != nil) {
  57. self.youpaipsvgaPlayer.videoItem = videoItem;
  58. [self.youpaipsvgaPlayer startAnimation];
  59. }
  60. } failureBlock:^(NSError * _Nullable error) {
  61. @strongify(self);
  62. self.youpaipsvgaPlayer.hidden = YES;
  63. }];
  64. [LCTools giftSVGAWithSvgaUrlStr:model.youpaippreview_img];
  65. }else{
  66. @weakify(self);
  67. [self.youpaipparser parseWithData:[LCTools giftSVGAWithSvgaUrlStr:model.youpaippreview_img] cacheKey:svgaCanchesPath completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
  68. @strongify(self);
  69. if (videoItem != nil) {
  70. self.youpaipsvgaPlayer.videoItem = videoItem;
  71. [self.youpaipsvgaPlayer startAnimation];
  72. }
  73. } failureBlock:^(NSError * _Nonnull error) {
  74. @strongify(self);
  75. self.youpaipsvgaPlayer.hidden = YES;
  76. }];
  77. }
  78. }
  79. @end