YOUPAILZEndLiveHintView.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. //
  2. // YOUPAILZEndLiveHintView.m
  3. // VQU
  4. //
  5. // Created by 肖浩然的mac on 2021/7/27.
  6. // Copyright © 2021 leo. All rights reserved.
  7. //
  8. #import "YOUPAILZEndLiveHintView.h"
  9. #import "YYAnimatedImageView.h"
  10. #import "YYImage.h"
  11. #import "YOUPAILZLiveCloseModel.h"
  12. #import "YOUPAILZLiveModel.h"
  13. #import "YOUPAILZLiveAudienceVC.h"
  14. @interface YOUPAILZEndLiveHintView ()
  15. @property (nonatomic, strong) YOUPAILZLiveCloseModel *youpaipcloseModelmodel;
  16. @property (nonatomic, strong) YOUPAILZEndLiveHintModel *youpaipmodel;
  17. @property (nonatomic, weak) UIButton *youpaipfollowBtn; // 关注按钮
  18. @property (nonatomic, weak) UIView *youpaiprecommendBgV; // 推荐背景View
  19. @property(nonatomic,strong)UIButton *transformBtn;//换一批
  20. @property(nonatomic,strong)UILabel *youpaiprecommendL;//换一批
  21. @end
  22. @implementation YOUPAILZEndLiveHintView
  23. - (instancetype)initWithFrame:(CGRect)frame Model:(YOUPAILZEndLiveHintModel *)model{
  24. if (self = [super initWithFrame:CGRectZero]) {
  25. _youpaipmodel = model;
  26. [self youpaifsetSubView];
  27. }
  28. return self;
  29. }
  30. - (void)youpaifsetSubView {
  31. self.frame = CGRectMake(0, KScreenHeight, KScreenWidth, KScreenHeight);
  32. [[UIApplication sharedApplication].keyWindow addSubview:self];
  33. // [UIView animateWithDuration:0.25 animations:^{
  34. self.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight);
  35. // }];
  36. [self youpaifinitUI];
  37. [self youpaiftransformBtnClick];
  38. }
  39. - (void)youpaifinitUI{
  40. UIImageView *bgV = [[UIImageView alloc] initWithFrame:self.bounds];
  41. bgV.contentMode = UIViewContentModeScaleAspectFill;
  42. bgV.userInteractionEnabled = YES;
  43. bgV.clipsToBounds = YES;
  44. [bgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:self.youpaipmodel.youpaipavatar]];
  45. [self addSubview:bgV];
  46. UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
  47. UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
  48. effectView.frame = bgV.bounds;
  49. [bgV addSubview:effectView];
  50. UIImageView *youpaipavatarImgV = [[UIImageView alloc] init];
  51. youpaipavatarImgV.contentMode = UIViewContentModeScaleAspectFill;
  52. youpaipavatarImgV.layer.cornerRadius = 50.0f;
  53. youpaipavatarImgV.clipsToBounds = YES;
  54. [youpaipavatarImgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:self.youpaipmodel.youpaipavatar]];
  55. [bgV addSubview:youpaipavatarImgV];
  56. [youpaipavatarImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  57. make.centerX.mas_equalTo(0);
  58. make.top.equalTo(50+NavBarHeight);
  59. make.size.mas_offset(CGSizeMake(100.0f, 100.0f));
  60. }];
  61. UILabel *youpaipnicknameL = [[UILabel alloc] init];
  62. [bgV addSubview:youpaipnicknameL];
  63. [youpaipnicknameL mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.top.mas_equalTo(youpaipavatarImgV.mas_bottom).offset(14.0f);
  65. make.centerX.mas_equalTo(0);
  66. make.height.mas_equalTo(16);
  67. }];
  68. youpaipnicknameL.font = LCFont16;
  69. youpaipnicknameL.textColor = HexColorFromRGB(0xffffff);
  70. youpaipnicknameL.text = self.youpaipmodel.youpaipnickname;
  71. UILabel *titleL = [[UILabel alloc] init];
  72. [bgV addSubview:titleL];
  73. [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
  74. make.top.mas_equalTo(youpaipnicknameL.mas_bottom).offset(26);
  75. make.centerX.mas_equalTo(0);
  76. make.height.mas_equalTo(19);
  77. }];
  78. titleL.font = [UIFont systemFontOfSize:19];
  79. titleL.textColor = HexColorFromRGB(0xffffff);
  80. titleL.text = @"你来晚了,直播已结束啦~";
  81. UILabel *youpaiprecommendL = [[UILabel alloc] init];
  82. self.youpaiprecommendL = youpaiprecommendL;
  83. [bgV addSubview:youpaiprecommendL];
  84. [youpaiprecommendL mas_makeConstraints:^(MASConstraintMaker *make) {
  85. make.top.mas_equalTo(titleL.mas_bottom).offset(48.0f);
  86. make.centerX.mas_equalTo(bgV.mas_centerX);
  87. make.height.mas_equalTo(12);
  88. }];
  89. youpaiprecommendL.font = LCFont12;
  90. youpaiprecommendL.textColor = HexColorFromRGB(0x9F9DA5);
  91. youpaiprecommendL.text = @"-------- 为您推荐,在线直播 --------";
  92. UIView *youpaiprecommendBgV = [[UIView alloc] init];
  93. [bgV addSubview:youpaiprecommendBgV];
  94. self.youpaiprecommendBgV = youpaiprecommendBgV;
  95. [youpaiprecommendBgV mas_makeConstraints:^(MASConstraintMaker *make) {
  96. make.centerX.equalTo(bgV.mas_centerX);
  97. make.top.equalTo(youpaiprecommendL.mas_bottom).offset(25.0f);
  98. make.height.offset((KScreenWidth - 102.0f) / 3.0f);
  99. }];
  100. UIButton *transformBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  101. self.transformBtn = transformBtn;
  102. transformBtn.titleLabel.font = LCFont12;
  103. transformBtn.layer.cornerRadius = 13.0f;
  104. transformBtn.clipsToBounds = YES;
  105. [transformBtn setTitle:@"换一批" forState:0];
  106. [transformBtn addTarget:self action:@selector(youpaiftransformBtnClick) forControlEvents:UIControlEventTouchUpInside];
  107. [transformBtn setTitleColor:HexColorFromRGB(0xffffff) forState:UIControlStateNormal];
  108. transformBtn.layer.borderColor = HexColorFromRGB(0xffffff).CGColor;
  109. transformBtn.layer.borderWidth = 0.5f;
  110. [bgV addSubview:transformBtn];
  111. [transformBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  112. make.centerX.equalTo(bgV.mas_centerX);
  113. make.top.equalTo(youpaiprecommendBgV.mas_bottom).offset(20.0f);
  114. make.size.mas_offset(CGSizeMake(69.0f, 26.0f));
  115. }];
  116. transformBtn.hidden = YES;
  117. [self youpaifcreateRecommendBtn];
  118. //退出
  119. UIButton *youpaipcloseBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  120. [youpaipcloseBtn addTarget:self action:@selector(youpaifcloseBtnClick) forControlEvents:UIControlEventTouchUpInside];
  121. [bgV addSubview:youpaipcloseBtn];
  122. [youpaipcloseBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  123. make.bottom.offset(-75.0f - SafeHeight);
  124. make.size.mas_offset(CGSizeMake(KScreenWidth - 120.0f, 48));
  125. make.centerX.mas_equalTo(0);
  126. }];
  127. youpaipcloseBtn.layer.cornerRadius = 48/2;
  128. youpaipcloseBtn.layer.masksToBounds = YES;
  129. [youpaipcloseBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - 120.0f, 48) FromColors:@[ZYGradientOneColor,ZYGradientTwoColor] ByGradientType:1] forState:UIControlStateNormal];
  130. [youpaipcloseBtn setTitle:@"退出" forState:UIControlStateNormal];
  131. [youpaipcloseBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  132. }
  133. - (void)youpaifcreateRecommendBtn{
  134. for (UIView *view in self.youpaiprecommendBgV.subviews) {
  135. [view removeFromSuperview];
  136. }
  137. CGFloat width = (KScreenWidth - 102.0f) / 3.0f;
  138. if (self.youpaipcloseModelmodel.youpaiplive.count<=0) {
  139. self.youpaiprecommendL.hidden = YES;
  140. self.transformBtn.hidden = YES;
  141. }else{
  142. self.youpaiprecommendL.hidden = NO;
  143. self.transformBtn.hidden = NO;
  144. }
  145. for (NSInteger i = 0; i < self.youpaipcloseModelmodel.youpaiplive.count; i ++) {
  146. YOUPAILZLiveListItemModel *itemModel = self.youpaipcloseModelmodel.youpaiplive[i];
  147. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  148. btn.imageView.contentMode = UIViewContentModeScaleAspectFill;
  149. btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentFill;
  150. btn.contentVerticalAlignment = UIControlContentVerticalAlignmentFill;
  151. btn.layer.cornerRadius = 8.0f;
  152. btn.clipsToBounds = YES;
  153. btn.contentMode = UIViewContentModeScaleAspectFill;
  154. [btn sd_setImageWithURL:[LCTools getImageUrlWithAddress:itemModel.youpaipcover_img] forState:UIControlStateNormal];
  155. btn.tag = i;
  156. [btn addTarget:self action:@selector(youpaifitemClick:) forControlEvents:UIControlEventTouchUpInside];
  157. [self.youpaiprecommendBgV addSubview:btn];
  158. [btn mas_makeConstraints:^(MASConstraintMaker *make) {
  159. make.left.offset(i * width + i * 4.0f);
  160. make.top.bottom.offset(0.0f);
  161. make.width.offset(width);
  162. if (i == self.youpaipcloseModelmodel.youpaiplive.count - 1) {
  163. make.right.offset(0.0f);
  164. }
  165. }];
  166. UIButton *youpaipleftTopBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  167. youpaipleftTopBtn.userInteractionEnabled = NO;
  168. youpaipleftTopBtn.frame = CGRectMake(0, 0, 41.0f, 14.0f);
  169. UIImage *bgImage = [LCTools ColorImage:youpaipleftTopBtn.mj_size FromColors:@[HexColorFromRGB(0xFF2ADD),HexColorFromRGB(0xFF6769)] ByGradientType:GradientLeftToRight];
  170. [youpaipleftTopBtn setBackgroundImage:bgImage forState:UIControlStateNormal];
  171. [youpaipleftTopBtn setBackgroundImage:bgImage forState:UIControlStateHighlighted];
  172. [LCTools clipCorner:UIRectCornerBottomRight View:youpaipleftTopBtn size:CGSizeMake(8.0f, 8.0f)];
  173. youpaipleftTopBtn.userInteractionEnabled = NO;
  174. [btn addSubview:youpaipleftTopBtn];
  175. [youpaipleftTopBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  176. make.top.left.offset(0.0f);
  177. make.size.mas_offset(CGSizeMake(41.0f, 14.0f));
  178. }];
  179. NSString *path = [[NSBundle mainBundle] pathForResource:@"ic_live_zhibozhong_28" ofType:@"gif"];
  180. YYAnimatedImageView *youpaipiconImgV = [[YYAnimatedImageView alloc] init];
  181. youpaipiconImgV.image = [YYImage imageWithData:[NSData dataWithContentsOfFile:path]];
  182. [youpaipleftTopBtn addSubview:youpaipiconImgV];
  183. [youpaipiconImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  184. make.left.offset(3.0f);
  185. make.centerY.equalTo(youpaipleftTopBtn.mas_centerY);
  186. make.size.mas_offset(CGSizeMake(9.5f, 9.5f));
  187. }];
  188. UILabel *youpaiptextL = [[UILabel alloc] init];
  189. youpaiptextL.font = LCFont(8.0f);
  190. youpaiptextL.textColor = [UIColor whiteColor];
  191. youpaiptextL.text = @"直播中";
  192. [youpaipleftTopBtn addSubview:youpaiptextL];
  193. [youpaiptextL mas_makeConstraints:^(MASConstraintMaker *make) {
  194. make.left.equalTo(youpaipiconImgV.mas_right).offset(1.5f);
  195. make.centerY.equalTo(youpaipleftTopBtn.mas_centerY);
  196. }];
  197. UIView *footerV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, 20.0f)];
  198. CAGradientLayer *gradientLayerBot = [CAGradientLayer layer];
  199. gradientLayerBot.frame = footerV.bounds;
  200. //设置渐变颜色数组,可以加透明度的渐变
  201. gradientLayerBot.colors = @[(__bridge id)[[UIColor whiteColor] colorWithAlphaComponent:0.0f].CGColor,(__bridge id)[[UIColor blackColor] colorWithAlphaComponent:0.1f].CGColor];
  202. //设置渐变区域的起始和终止位置(范围为0-1)
  203. gradientLayerBot.startPoint = CGPointMake(0, 0.5f);
  204. gradientLayerBot.endPoint = CGPointMake(0, 1);
  205. [footerV.layer addSublayer:gradientLayerBot];
  206. [btn addSubview:footerV];
  207. [footerV mas_makeConstraints:^(MASConstraintMaker *make) {
  208. make.left.bottom.right.offset(0.0f);
  209. make.height.offset(44.0f);
  210. }];
  211. UILabel *youpaipnicknameL = [[UILabel alloc] init];
  212. youpaipnicknameL.textColor = [UIColor whiteColor];
  213. youpaipnicknameL.font = LCFont(10);
  214. youpaipnicknameL.text = itemModel.youpaipanchor_name;
  215. [footerV addSubview:youpaipnicknameL];
  216. [youpaipnicknameL mas_makeConstraints:^(MASConstraintMaker *make) {
  217. make.left.offset(5.0f);
  218. make.bottom.offset(-3.0f);
  219. make.right.offset(-5.0f);
  220. }];
  221. }
  222. }
  223. - (void)youpaiftransformBtnClick{
  224. @weakify(self);
  225. [LCHttpHelper requestWithURLString:GetUserCloseLive parameters:@{@"is_refresh_rand":@(1)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  226. @strongify(self);
  227. NSDictionary* dict = (NSDictionary*)responseObject;
  228. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  229. if (code==0) {//成功
  230. YOUPAILZLiveCloseModel *model = [YOUPAILZLiveCloseModel mj_objectWithKeyValues:[dict objectForKey:@"data"]];
  231. self.youpaipcloseModelmodel = model;
  232. [self youpaifcreateRecommendBtn];
  233. }else{
  234. [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
  235. }
  236. } failure:^(NSError *error) {
  237. [ZCHUDHelper showTitle:error.localizedDescription];
  238. }];
  239. }
  240. - (void)youpaifitemClick:(UIButton *)sender{
  241. YOUPAILZLiveListItemModel *model = self.youpaipcloseModelmodel.youpaiplive[sender.tag];
  242. // if (self.youpaipitemClickBlock != nil) {
  243. // self.youpaipitemClickBlock(self.youpaipcloseModelmodel.live[sender.tag]);
  244. // }
  245. [ZCHUDHelper showWithStatus:nil];
  246. @weakify(self);
  247. [LCHttpHelper requestWithURLString:JoinLive parameters:@{@"room_id":model.youpaiproom_id} needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  248. @strongify(self);
  249. NSDictionary* dict = (NSDictionary*)responseObject;
  250. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  251. if (code == 0) {
  252. [ZCHUDHelper dismiss];
  253. [[YOUPAILZChatRoomManager shareManager] youpaifcloseChatRoom];
  254. YOUPAILZLiveModel *youpaipliveModel = [YOUPAILZLiveModel mj_objectWithKeyValues:[dict objectForKey:@"data"]];
  255. if(youpaipliveModel.youpaiptype == 0){
  256. [UIView animateWithDuration:0.0 animations:^{
  257. self.frame = CGRectMake(0, KScreenHeight, KScreenWidth, KScreenHeight);
  258. } completion:^(BOOL finished) {
  259. [self removeFromSuperview];
  260. }];
  261. YOUPAILZEndLiveHintModel *model1 = [YOUPAILZEndLiveHintModel mj_objectWithKeyValues:dict[@"data"][@"user_info"]];
  262. YOUPAILZEndLiveHintView *view = [[YOUPAILZEndLiveHintView alloc]initWithFrame:CGRectZero Model:model1];
  263. }else{
  264. [ZCHUDHelper dismiss];
  265. [UIView animateWithDuration:0.0 animations:^{
  266. self.frame = CGRectMake(0, KScreenHeight, KScreenWidth, KScreenHeight);
  267. } completion:^(BOOL finished) {
  268. [self removeFromSuperview];
  269. }];
  270. [LCSaveData saveLiveRankTopThere:youpaipliveModel.youpaiprank_top_three];
  271. YOUPAILZLiveAudienceVC *audienceVC = [[YOUPAILZLiveAudienceVC alloc] initWithModel:youpaipliveModel];
  272. [[LCTools getCurrentVC].navigationController pushViewController:audienceVC animated:YES];
  273. }
  274. }else{
  275. [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
  276. }
  277. } failure:^(NSError *error) {
  278. [ZCHUDHelper showTitle:error.localizedDescription];
  279. }];
  280. }
  281. - (void)youpaifcloseBtnClick{
  282. [UIView animateWithDuration:0.0 animations:^{
  283. self.frame = CGRectMake(0, KScreenHeight, KScreenWidth, KScreenHeight);
  284. } completion:^(BOOL finished) {
  285. [self removeFromSuperview];
  286. }];
  287. }
  288. /// 虚线
  289. - (CAShapeLayer *)youpaifdrawDashedLine{
  290. CAShapeLayer *shapeLayer = [CAShapeLayer layer];
  291. [shapeLayer setBounds:self.bounds];
  292. [shapeLayer setPosition:self.center];
  293. [shapeLayer setFillColor:[[UIColor clearColor] CGColor]];
  294. // 设置虚线颜色为blackColor
  295. [shapeLayer setStrokeColor:[HexColorFromRGB(0x999999) CGColor]];
  296. // 3.0f设置虚线的宽度
  297. [shapeLayer setLineWidth:0.5f];
  298. [shapeLayer setLineJoin:kCALineJoinRound];
  299. // 3=线的宽度 1=每条线的间距
  300. [shapeLayer setLineDashPattern:
  301. [NSArray arrayWithObjects:[NSNumber numberWithInt:5.0f],
  302. [NSNumber numberWithInt:1.0f],nil]];
  303. // Setup the path
  304. CGMutablePathRef path = CGPathCreateMutable();
  305. CGPathMoveToPoint(path, NULL, 0, 0);
  306. CGPathAddLineToPoint(path, NULL, KScreenWidth - 136.0f,0);
  307. [shapeLayer setPath:path];
  308. CGPathRelease(path);
  309. return shapeLayer;
  310. }
  311. @end