YOUPAILZChatRoomBgImgCell.m 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //
  2. // YOUPAILZChatRoomBgImgCell.m
  3. // MSYOUPAI
  4. //
  5. // Created by CY on 2022/1/8.
  6. // Copyright © 2022 MS. All rights reserved.
  7. //
  8. #import "YOUPAILZChatRoomBgImgCell.h"
  9. #import <SVGAPlayer.h>
  10. #import <SVGAParser.h>
  11. @interface YOUPAILZChatRoomBgImgCell ()
  12. @property (nonatomic, weak) UIImageView *bgImgV;
  13. @property (nonatomic, strong) SVGAPlayer *youpaipsvgaPlayer;
  14. @property (nonatomic, strong) SVGAParser *youpaipparser;
  15. @end
  16. @implementation YOUPAILZChatRoomBgImgCell
  17. -(instancetype)initWithFrame:(CGRect)frame{
  18. self = [super initWithFrame:frame];
  19. if (self) {
  20. [self youpaifinitUI];
  21. }
  22. return self;
  23. }
  24. - (void)youpaifinitUI{
  25. UIImageView *bgImgV = [[UIImageView alloc] init];
  26. bgImgV.contentMode = UIViewContentModeScaleAspectFill;
  27. bgImgV.layer.cornerRadius = ScaleSize(10.0f);
  28. bgImgV.clipsToBounds = YES;
  29. bgImgV.layer.borderColor = HexColorFromRGB(0xF4003F).CGColor;
  30. [self.contentView addSubview:bgImgV];
  31. self.bgImgV = bgImgV;
  32. [bgImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  33. make.left.top.bottom.right.offset(0.0f);
  34. }];
  35. self.youpaipsvgaPlayer = [[SVGAPlayer alloc] initWithFrame:self.bounds];
  36. self.youpaipsvgaPlayer.contentMode = UIViewContentModeScaleAspectFill;
  37. self.youpaipsvgaPlayer.layer.cornerRadius = ScaleSize(10.0f);
  38. self.youpaipsvgaPlayer.clipsToBounds = YES;
  39. self.youpaipsvgaPlayer.layer.borderColor = HexColorFromRGB(0xF4003F).CGColor;
  40. [self.contentView addSubview:self.youpaipsvgaPlayer];
  41. self.youpaipsvgaPlayer.hidden = YES;
  42. self.youpaipsvgaPlayer.loops = 0;
  43. self.youpaipsvgaPlayer.clearsAfterStop = true;
  44. self.youpaipparser = [[SVGAParser alloc] init];
  45. self.youpaipsvgaPlayer.userInteractionEnabled = NO;
  46. }
  47. - (void)youpaifreloadWithModel:(YOUPAILZChatRoomBgImgModel *)model{
  48. if (model.isSelected) {
  49. self.bgImgV.layer.borderWidth = 1.0f;
  50. self.youpaipsvgaPlayer.layer.borderWidth = 1.0f;
  51. }else{
  52. self.bgImgV.layer.borderWidth = 0.0f;
  53. self.youpaipsvgaPlayer.layer.borderWidth = 0.0f;
  54. }
  55. self.bgImgV.hidden = YES;
  56. self.youpaipsvgaPlayer.hidden = YES;
  57. if ([model.youpaipimg_url containsString:@".svga"]) {
  58. self.youpaipsvgaPlayer.hidden = NO;
  59. [self.youpaipsvgaPlayer stopAnimation];
  60. NSString* svgaName = [[model.youpaipimg_url componentsSeparatedByString:@"/"] lastObject];
  61. NSString* svgaCanchesPath= [[NSString alloc]initWithFormat:@"%@/%@/%@",CachesPath,@"SVGA",svgaName];
  62. if (![LCTools giftSVGAWithSvgaUrlStr:model.youpaipimg_url]){
  63. NSString* urlStr = [NSString stringWithFormat:@"%@/%@",[LCSaveData getImageUrl]?[LCSaveData getImageUrl]:BaseImgUrl,model.youpaipimg_url];
  64. @weakify(self);
  65. [self.youpaipparser parseWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
  66. @strongify(self);
  67. if (videoItem != nil) {
  68. self.youpaipsvgaPlayer.videoItem = videoItem;
  69. [self.youpaipsvgaPlayer startAnimation];
  70. }
  71. } failureBlock:^(NSError * _Nullable error) {
  72. @strongify(self);
  73. self.youpaipsvgaPlayer.hidden = YES;
  74. }];
  75. [LCTools giftSVGAWithSvgaUrlStr:model.youpaipimg_url];
  76. }else{
  77. @weakify(self);
  78. [self.youpaipparser parseWithData:[LCTools giftSVGAWithSvgaUrlStr:model.youpaipimg_url] cacheKey:svgaCanchesPath completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
  79. @strongify(self);
  80. if (videoItem != nil) {
  81. self.youpaipsvgaPlayer.videoItem = videoItem;
  82. [self.youpaipsvgaPlayer startAnimation];
  83. }
  84. } failureBlock:^(NSError * _Nonnull error) {
  85. @strongify(self);
  86. self.youpaipsvgaPlayer.hidden = YES;
  87. }];
  88. }
  89. }else{
  90. self.bgImgV.hidden = NO;
  91. [self.bgImgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:model.youpaipimg_url]];
  92. }
  93. }
  94. @end