YOUPAILZVipHeaderView.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. //
  2. // YOUPAILZVipHeaderView.m
  3. // VQU
  4. //
  5. // Created by CY on 2021/8/21.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAILZVipHeaderView.h"
  9. #import <SVGAPlayer.h>
  10. #import <SVGAParser.h>
  11. @interface YOUPAILZVipHeaderView ()<SVGAPlayerDelegate>
  12. @property (nonatomic,weak)UIImageView *youpaipvipImgV; // vip 标识
  13. @property (nonatomic,weak)UILabel *youpaipvipCoinL; // 贵族币
  14. @property (nonatomic,weak)UILabel *youpaipvalidityL;// 有效期
  15. /// 座驾
  16. @property (nonatomic,weak)UIImageView *youpaipdrivePedestalImgV;
  17. @property (nonatomic, strong) SVGAPlayer *youpaipsvgaPlayer;
  18. @property (nonatomic, strong) SVGAParser *youpaipparser;
  19. @property (nonatomic,weak)UILabel *youpaipvipPrivilegeTitleL; // 贵族特权
  20. @property (nonatomic,strong) YOUPAILZVipInfoModel *youpaipmodel;
  21. @end
  22. @implementation YOUPAILZVipHeaderView
  23. - (instancetype)initWithFrame:(CGRect)frame{
  24. if (self = [super initWithFrame:frame]) {
  25. [self youpaifinitUI];
  26. }
  27. return self;
  28. }
  29. - (void)youpaifinitUI{
  30. self.backgroundColor = LCBkgColor;
  31. UIImageView *bgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"vqu_images_ic_vip_header_bg"]];
  32. [self addSubview:bgV];
  33. [bgV mas_makeConstraints:^(MASConstraintMaker *make) {
  34. make.left.right.offset(0.0f);
  35. make.top.offset(ScaleSize(20.0f));
  36. make.height.offset(ScaleSize(232.0f));
  37. }];
  38. UIImageView *vipImgV = [[UIImageView alloc] init];
  39. vipImgV.contentMode = UIViewContentModeScaleAspectFit;
  40. [self addSubview:vipImgV];
  41. self.youpaipvipImgV = vipImgV;
  42. [vipImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.centerX.equalTo(self.mas_centerX);
  44. make.top.offset(ScaleSize(20.0f));
  45. make.size.mas_offset(CGSizeMake(ScaleSize(136.0f), ScaleSize(122.0f)));
  46. }];
  47. UIButton *vipCoinBgBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  48. vipCoinBgBtn.layer.cornerRadius = 10.0f;
  49. vipCoinBgBtn.clipsToBounds = YES;
  50. vipCoinBgBtn.layer.borderColor = HexColorFromRGB(0xFDCC88).CGColor;
  51. vipCoinBgBtn.layer.borderWidth = 0.5f;
  52. [vipCoinBgBtn addTarget:self action:@selector(youpaifvipCoinBgBtnClick) forControlEvents:UIControlEventTouchUpInside];
  53. [self addSubview:vipCoinBgBtn];
  54. [vipCoinBgBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.top.equalTo(vipImgV.mas_bottom).offset(ScaleSize(10.0f));
  56. make.centerX.equalTo(self.mas_centerX);
  57. make.height.offset(20.0f);
  58. make.width.greaterThanOrEqualTo(122.0f);
  59. }];
  60. UIImageView *rightArraw = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"vqu_images_ic_vip_coin_arrow"]];
  61. [vipCoinBgBtn addSubview:rightArraw];
  62. [rightArraw mas_makeConstraints:^(MASConstraintMaker *make) {
  63. make.right.offset(-10.0f);
  64. make.centerY.equalTo(vipCoinBgBtn.mas_centerY);
  65. make.size.mas_offset(CGSizeMake(7.0f, 10.0f));
  66. }];
  67. UILabel *vipCoinL = [[UILabel alloc] init];
  68. vipCoinL.font = LCFont14;
  69. vipCoinL.textAlignment = NSTextAlignmentCenter;
  70. vipCoinL.textColor = HexColorFromRGB(0xFDCC88);
  71. vipCoinL.text = @"贵族币:0";
  72. [vipCoinBgBtn addSubview:vipCoinL];
  73. self.youpaipvipCoinL = vipCoinL;
  74. [vipCoinL mas_makeConstraints:^(MASConstraintMaker *make) {
  75. make.left.offset(10.0f);
  76. make.top.bottom.offset(0.0f);
  77. make.right.equalTo(rightArraw.mas_left).offset(-8.0f);
  78. }];
  79. UILabel *validityL = [[UILabel alloc] init];
  80. validityL.font = LCFont(11.0f);
  81. validityL.textColor = [[UIColor whiteColor] colorWithAlphaComponent:0.65f];
  82. validityL.text = @"暂未开通";
  83. [self addSubview:validityL];
  84. self.youpaipvalidityL = validityL;
  85. [validityL mas_makeConstraints:^(MASConstraintMaker *make) {
  86. make.top.equalTo(vipCoinBgBtn.mas_bottom).offset(ScaleSize(10.0f));
  87. make.centerX.equalTo(self.mas_centerX);
  88. }];
  89. UIView *footerBgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth + 1.0f, ScaleSize(86.0f))];
  90. footerBgView.backgroundColor = HexColorFromRGB(0x986542);
  91. [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerTopRight View:footerBgView size:CGSizeMake(20.0f, 20.0f)];
  92. [self addSubview:footerBgView];
  93. [footerBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  94. make.bottom.offset(0.0f);
  95. make.left.offset(-0.5f);
  96. make.right.offset(0.5f);
  97. make.height.offset(ScaleSize(86.0f));
  98. }];
  99. UIImageView *drivePedestalImgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"vqu_images_ic_vip_drive_pedestal"]];
  100. drivePedestalImgV.userInteractionEnabled = YES;
  101. [self addSubview:drivePedestalImgV];
  102. self.youpaipdrivePedestalImgV = drivePedestalImgV;
  103. [drivePedestalImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  104. make.right.offset(ScaleSize(-14.0f));
  105. make.bottom.equalTo(footerBgView.mas_top);
  106. make.size.mas_offset(CGSizeMake(ScaleSize(86.0f), ScaleSize(94.0f)));
  107. }];
  108. self.youpaipsvgaPlayer = [[SVGAPlayer alloc] init];
  109. self.youpaipsvgaPlayer.contentMode = UIViewContentModeScaleAspectFit;
  110. self.youpaipsvgaPlayer.delegate = self;
  111. [self addSubview:self.youpaipsvgaPlayer];
  112. [self.youpaipsvgaPlayer mas_makeConstraints:^(MASConstraintMaker *make) {
  113. make.centerX.equalTo(drivePedestalImgV.mas_centerX);
  114. make.bottom.equalTo(drivePedestalImgV.mas_top).offset(ScaleSize(24.0f));
  115. make.size.mas_offset(CGSizeMake(ScaleSize(72.0f), ScaleSize(72.0f)));
  116. }];
  117. UITapGestureRecognizer *panGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(youpaiftouchCarClick)];
  118. [self.youpaipsvgaPlayer addGestureRecognizer:panGes];
  119. UITapGestureRecognizer *panGes1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(youpaiftouchCarClick)];
  120. [drivePedestalImgV addGestureRecognizer:panGes1];
  121. self.youpaipsvgaPlayer.loops = 0;
  122. self.youpaipsvgaPlayer.clearsAfterStop = true;
  123. self.youpaipparser = [[SVGAParser alloc] init];
  124. UIView *footerV = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, KScreenWidth, ScaleSize(85.5f))];
  125. footerV.backgroundColor = HexColorFromRGB(0x2A2935);
  126. [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerTopRight View:footerV size:CGSizeMake(19.5f, 19.5f)];
  127. [footerBgView addSubview:footerV];
  128. [footerV mas_makeConstraints:^(MASConstraintMaker *make) {
  129. make.bottom.offset(0.0f);
  130. make.left.top.offset(0.5f);
  131. make.right.offset(-0.5f);
  132. }];
  133. UILabel *vipPrivilegeTitleL = [[UILabel alloc] init];
  134. vipPrivilegeTitleL.textColor = HexColorFromRGB(0xFDCC88);
  135. vipPrivilegeTitleL.font = LCFont14;
  136. vipPrivilegeTitleL.text = @"专属特权 0/21";
  137. [footerV addSubview:vipPrivilegeTitleL];
  138. self.youpaipvipPrivilegeTitleL = vipPrivilegeTitleL;
  139. [vipPrivilegeTitleL mas_makeConstraints:^(MASConstraintMaker *make) {
  140. make.centerX.equalTo(footerV.mas_centerX);
  141. make.top.offset(ScaleSize(30.0f));
  142. }];
  143. UIImageView *leftImgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"vqu_images_ic_vip_privilege_left"]];
  144. [footerV addSubview:leftImgV];
  145. [leftImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  146. make.right.equalTo(vipPrivilegeTitleL.mas_left).offset(-6.0f);
  147. make.centerY.equalTo(vipPrivilegeTitleL.mas_centerY);
  148. make.size.mas_offset(CGSizeMake(12.0f, 9.0f));
  149. }];
  150. UIImageView *rightImgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"vqu_images_ic_vip_privilege_right"]];
  151. [footerV addSubview:rightImgV];
  152. [rightImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  153. make.left.equalTo(vipPrivilegeTitleL.mas_right).offset(6.0f);
  154. make.centerY.equalTo(vipPrivilegeTitleL.mas_centerY);
  155. make.size.mas_offset(CGSizeMake(12.0f, 9.0f));
  156. }];
  157. UIImageView *bottomImgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"vqu_images_ic_vip_privilege_bottom"]];
  158. [footerV addSubview:bottomImgV];
  159. [bottomImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  160. make.top.equalTo(vipPrivilegeTitleL.mas_bottom).offset(4.0f);
  161. make.centerX.equalTo(vipPrivilegeTitleL.mas_centerX);
  162. make.size.mas_offset(CGSizeMake(81.0f, 8.0f));
  163. }];
  164. }
  165. - (void)youpaifreloadWithModel:(YOUPAILZVipInfoModel *)model{
  166. if (model == nil) {
  167. return;
  168. }
  169. self.youpaipmodel = model;
  170. [self.youpaipvipImgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:model.youpaipnoble.youpaipimg]];
  171. self.youpaipvipCoinL.text = [NSString stringWithFormat:@"贵族币:%@",model.youpaipnoble_coin];
  172. if([model.youpaippay_info.youpaipstatus isEqual:@"over"]){
  173. self.youpaipvalidityL.textColor = HexColorFromRGB(0xF4003F);
  174. }else{
  175. self.youpaipvalidityL.textColor = [[UIColor whiteColor] colorWithAlphaComponent:0.65f];
  176. }
  177. self.youpaipvalidityL.text = model.youpaippay_info.youpaipexpire;
  178. self.youpaipvipPrivilegeTitleL.text = [NSString stringWithFormat:@"专属特权 %@/%@",model.youpaiphas_privilege_num,model.youpaiptotal_privilege];
  179. [self.youpaipsvgaPlayer stopAnimation];
  180. self.youpaipdrivePedestalImgV.hidden = YES;
  181. if (model.youpaipcar.youpaippreview_img.length != 0) {
  182. self.youpaipdrivePedestalImgV.hidden = NO;
  183. }
  184. NSString* svgaName = [[model.youpaipcar.youpaippreview_img componentsSeparatedByString:@"/"] lastObject];
  185. NSString* svgaCanchesPath= [[NSString alloc]initWithFormat:@"%@/%@/%@",CachesPath,@"SVGA",svgaName];
  186. [self.youpaipsvgaPlayer stopAnimation];
  187. if (![LCTools giftSVGAWithSvgaUrlStr:model.youpaipcar.youpaippreview_img]){
  188. NSString* urlStr = [NSString stringWithFormat:@"%@/%@",[LCSaveData getImageUrl]?[LCSaveData getImageUrl]:BaseImgUrl,model.youpaipcar.youpaippreview_img];
  189. @weakify(self);
  190. [self.youpaipparser parseWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
  191. @strongify(self);
  192. if (videoItem != nil) {
  193. self.youpaipsvgaPlayer.videoItem = videoItem;
  194. [self.youpaipsvgaPlayer startAnimation];
  195. }
  196. } failureBlock:^(NSError * _Nullable error) {
  197. }];
  198. [LCTools giftSVGAWithSvgaUrlStr:model.youpaipcar.youpaippreview_img];
  199. }else{
  200. @weakify(self);
  201. [self.youpaipparser parseWithData:[LCTools giftSVGAWithSvgaUrlStr:model.youpaipcar.youpaippreview_img] cacheKey:svgaCanchesPath completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
  202. @strongify(self);
  203. if (videoItem != nil) {
  204. self.youpaipsvgaPlayer.videoItem = videoItem;
  205. [self.youpaipsvgaPlayer startAnimation];
  206. }
  207. } failureBlock:^(NSError * _Nonnull error) {
  208. }];
  209. }
  210. }
  211. - (void)youpaifvipCoinBgBtnClick{
  212. if(self.clickVipCoinBlock != nil){
  213. self.clickVipCoinBlock();
  214. }
  215. }
  216. - (void)youpaiftouchCarClick{
  217. if(self.clickCarBlock != nil){
  218. self.clickCarBlock();
  219. }
  220. }
  221. @end