123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- //
- // YOUPAILZChatRoomBgImgCell.m
- // MSYOUPAI
- //
- // Created by CY on 2022/1/8.
- // Copyright © 2022 MS. All rights reserved.
- //
- #import "YOUPAILZChatRoomBgImgCell.h"
- #import <SVGAPlayer.h>
- #import <SVGAParser.h>
- @interface YOUPAILZChatRoomBgImgCell ()
- @property (nonatomic, weak) UIImageView *bgImgV;
- @property (nonatomic, strong) SVGAPlayer *youpaipsvgaPlayer;
- @property (nonatomic, strong) SVGAParser *youpaipparser;
- @end
- @implementation YOUPAILZChatRoomBgImgCell
- -(instancetype)initWithFrame:(CGRect)frame{
- self = [super initWithFrame:frame];
- if (self) {
- [self youpaifinitUI];
- }
- return self;
- }
- - (void)youpaifinitUI{
- UIImageView *bgImgV = [[UIImageView alloc] init];
- bgImgV.contentMode = UIViewContentModeScaleAspectFill;
- bgImgV.layer.cornerRadius = ScaleSize(10.0f);
- bgImgV.clipsToBounds = YES;
- bgImgV.layer.borderColor = HexColorFromRGB(0xF4003F).CGColor;
- [self.contentView addSubview:bgImgV];
- self.bgImgV = bgImgV;
- [bgImgV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.bottom.right.offset(0.0f);
- }];
-
- self.youpaipsvgaPlayer = [[SVGAPlayer alloc] initWithFrame:self.bounds];
- self.youpaipsvgaPlayer.contentMode = UIViewContentModeScaleAspectFill;
- self.youpaipsvgaPlayer.layer.cornerRadius = ScaleSize(10.0f);
- self.youpaipsvgaPlayer.clipsToBounds = YES;
- self.youpaipsvgaPlayer.layer.borderColor = HexColorFromRGB(0xF4003F).CGColor;
- [self.contentView addSubview:self.youpaipsvgaPlayer];
- self.youpaipsvgaPlayer.hidden = YES;
- self.youpaipsvgaPlayer.loops = 0;
- self.youpaipsvgaPlayer.clearsAfterStop = true;
- self.youpaipparser = [[SVGAParser alloc] init];
- self.youpaipsvgaPlayer.userInteractionEnabled = NO;
- }
- - (void)youpaifreloadWithModel:(YOUPAILZChatRoomBgImgModel *)model{
- if (model.isSelected) {
- self.bgImgV.layer.borderWidth = 1.0f;
- self.youpaipsvgaPlayer.layer.borderWidth = 1.0f;
- }else{
- self.bgImgV.layer.borderWidth = 0.0f;
- self.youpaipsvgaPlayer.layer.borderWidth = 0.0f;
- }
- self.bgImgV.hidden = YES;
- self.youpaipsvgaPlayer.hidden = YES;
-
- if ([model.youpaipimg_url containsString:@".svga"]) {
- self.youpaipsvgaPlayer.hidden = NO;
- [self.youpaipsvgaPlayer stopAnimation];
-
- NSString* svgaName = [[model.youpaipimg_url componentsSeparatedByString:@"/"] lastObject];
- NSString* svgaCanchesPath= [[NSString alloc]initWithFormat:@"%@/%@/%@",CachesPath,@"SVGA",svgaName];
- if (![LCTools giftSVGAWithSvgaUrlStr:model.youpaipimg_url]){
- NSString* urlStr = [NSString stringWithFormat:@"%@/%@",[LCSaveData getImageUrl]?[LCSaveData getImageUrl]:BaseImgUrl,model.youpaipimg_url];
- @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.youpaipimg_url];
- }else{
- @weakify(self);
- [self.youpaipparser parseWithData:[LCTools giftSVGAWithSvgaUrlStr:model.youpaipimg_url] 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;
- }];
- }
-
- }else{
- self.bgImgV.hidden = NO;
- [self.bgImgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:model.youpaipimg_url]];
- }
-
-
-
- }
- @end
|