// // YOUPAILZCarDressHeaderView.m // VQU // // Created by CY on 2021/8/23. // Copyright © 2021 MS. All rights reserved. // #import "YOUPAILZCarDressHeaderView.h" #import #import @interface YOUPAILZCarDressHeaderView () @property (nonatomic, strong) SVGAPlayer *youpaipsvgaPlayer; @property (nonatomic, strong) SVGAParser *youpaipparser; @end @implementation YOUPAILZCarDressHeaderView - (instancetype)initWithFrame:(CGRect)frame{ if (self = [super initWithFrame:frame]) { [self youpaifinitUI]; } return self; } - (void)youpaifinitUI{ UIImageView *bgImgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"vqu_images_ic_profile_dress_bg"]]; [self addSubview:bgImgV]; [bgImgV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.top.bottom.right.offset(0.0f); }]; bgImgV.userInteractionEnabled = YES; self.youpaipsvgaPlayer = [[SVGAPlayer alloc] init]; self.youpaipsvgaPlayer.contentMode = UIViewContentModeScaleAspectFit; self.youpaipsvgaPlayer.delegate = self; [self addSubview:self.youpaipsvgaPlayer]; [self.youpaipsvgaPlayer mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self); make.centerY.equalTo(self); make.size.mas_offset(CGSizeMake(135.0f, 135.0f)); }]; self.youpaipsvgaPlayer.hidden = YES; self.youpaipsvgaPlayer.loops = 0; self.youpaipsvgaPlayer.clearsAfterStop = true; self.youpaipparser = [[SVGAParser alloc] init]; } - (void)youpaifreloadWithModel:(YOUPAILZDressModel *)model{ [self.youpaipsvgaPlayer stopAnimation]; if (![model.youpaippreview_img isEqualToString:@""]) { self.youpaipsvgaPlayer.hidden = NO; } NSString* svgaName = [[model.youpaippreview_img componentsSeparatedByString:@"/"] lastObject]; NSString* svgaCanchesPath= [[NSString alloc]initWithFormat:@"%@/%@/%@",CachesPath,@"SVGA",svgaName]; [self.youpaipsvgaPlayer stopAnimation]; if (![LCTools giftSVGAWithSvgaUrlStr:model.youpaippreview_img]){ NSString* urlStr = [NSString stringWithFormat:@"%@/%@",[LCSaveData getImageUrl]?[LCSaveData getImageUrl]:BaseImgUrl,model.youpaippreview_img]; @weakify(self); [self.youpaipparser parseWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) { @strongify(self); if (videoItem != nil) { self.youpaipsvgaPlayer.videoItem = videoItem; [self.youpaipsvgaPlayer startAnimation]; } } failureBlock:^(NSError * _Nullable error) { @strongify(self); self.youpaipsvgaPlayer.hidden = YES; }]; [LCTools giftSVGAWithSvgaUrlStr:model.youpaippreview_img]; }else{ @weakify(self); [self.youpaipparser parseWithData:[LCTools giftSVGAWithSvgaUrlStr:model.youpaippreview_img] cacheKey:svgaCanchesPath completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) { @strongify(self); if (videoItem != nil) { self.youpaipsvgaPlayer.videoItem = videoItem; [self.youpaipsvgaPlayer startAnimation]; } } failureBlock:^(NSError * _Nonnull error) { @strongify(self); self.youpaipsvgaPlayer.hidden = YES; }]; } } @end