YOUPAILZLiveBarrageTool.m 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //
  2. // YOUPAILZLiveBarrageTool.m
  3. // VQU
  4. //
  5. // Created by CY on 2021/8/30.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAILZLiveBarrageTool.h"
  9. #import "YOUPAILZAvatarView.h"
  10. #import "YOUPAILZLevelView.h"
  11. @implementation YOUPAILZLiveBarrageTool
  12. /// 处理VIP进场弹幕消息
  13. + (UIView *)youpaifhandleVipBarrageAttachment:(YOUPAILZLiveVipBarrageAttachment *)barrageAttachment{
  14. UIView *bgV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 220.0f, 43.0f)];
  15. UIImageView *boxImgV = [[UIImageView alloc] initWithFrame:CGRectMake(17.5f, 7.0f, bgV.mj_w - 17.5f, bgV.mj_h - 7.0f)];
  16. [boxImgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:barrageAttachment.b_box]];
  17. [bgV addSubview:boxImgV];
  18. YOUPAILZAvatarView *youpaipavatarView = [YOUPAILZAvatarView youpaifavatarViewWithFrame:CGRectMake(0, 0, 34.0f, 34.0f) avatarURL:[LCTools getImageUrlWithAddress:barrageAttachment.avatar] personalityBoxURL:[LCTools getImageUrlWithAddress:barrageAttachment.avatar_frame]];
  19. [bgV addSubview:youpaipavatarView];
  20. [youpaipavatarView mas_makeConstraints:^(MASConstraintMaker *make) {
  21. make.left.offset(0.0f);
  22. make.centerY.equalTo(bgV);
  23. make.size.mas_offset(CGSizeMake(34.0f, 34.0f));
  24. }];
  25. UILabel *descL = [[UILabel alloc] initWithFrame:CGRectMake(30.0f, 4.0f, boxImgV.mj_w - (30.0f + 20.0f), 25.0f)];
  26. descL.textColor = [UIColor whiteColor];
  27. descL.font = LCFont13;
  28. // descL.text = barrageAttachment.des;
  29. [boxImgV addSubview:descL];
  30. if (barrageAttachment.name.length > 3) {
  31. barrageAttachment.name = [NSString stringWithFormat:@"%@…",[barrageAttachment.name substringToIndex:3]];
  32. }
  33. NSString *moneyText = barrageAttachment.noble_name;
  34. NSRange priceRange = NSMakeRange(moneyText.length + 1, barrageAttachment.name.length);
  35. moneyText = [NSString stringWithFormat:@"%@ %@ 驾临!",moneyText,barrageAttachment.name];
  36. NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:moneyText];
  37. [attrStr addAttribute:NSForegroundColorAttributeName value:HexColorFromRGB(0xFFDD8D) range:priceRange];
  38. descL.attributedText = attrStr;
  39. return bgV;
  40. }
  41. /// 处理榜单进场弹幕消息
  42. + (UIView *)youpaifhandleBarrageAttachment:(YOUPAILZLiveBarrageAttachment *)barrageAttachment{
  43. UIView *bgV = [[UIView alloc] init];
  44. UIView *barrageView = [[UIView alloc] init];
  45. barrageView.backgroundColor = [UIColor clearColor];
  46. [bgV addSubview:barrageView];
  47. [barrageView mas_makeConstraints:^(MASConstraintMaker *make) {
  48. make.left.top.right.bottom.offset(0.0f);
  49. }];
  50. CGSize rankSize = CGSizeMake(21.0f, 18.0f);
  51. UIImageView *youpaipboardImgV = [[UIImageView alloc] init];
  52. [bgV addSubview:youpaipboardImgV];
  53. [youpaipboardImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.left.offset(5.0f);
  55. make.centerY.equalTo(bgV);
  56. make.size.mas_offset(rankSize);
  57. }];
  58. youpaipboardImgV.hidden = YES;
  59. CGFloat totalWidth = 0.0f;
  60. BOOL hasRank = NO;
  61. if (barrageAttachment.rankInfo != nil && [barrageAttachment.rankInfo.allKeys containsObject:@"img"]) {
  62. hasRank = YES;
  63. }
  64. if (hasRank) {
  65. youpaipboardImgV.hidden = NO;
  66. totalWidth = 7.0f + rankSize.width + 5.0f;
  67. [youpaipboardImgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:barrageAttachment.rankInfo[@"img"]]];
  68. }
  69. /// 等级
  70. YOUPAILZLevelView *youpaiplevelView = [[YOUPAILZLevelView alloc] init];
  71. [bgV addSubview:youpaiplevelView];
  72. NSString *levelName = [barrageAttachment.gradeInfo objectForKey:@"grade_name"];
  73. NSInteger level = [[barrageAttachment.gradeInfo objectForKey:@"grade"] integerValue];
  74. NSString *levelIcon = [barrageAttachment.gradeInfo objectForKey:@"img1"];
  75. CGFloat levelIconWidth = [[barrageAttachment.gradeInfo objectForKey:@"icon_width"] floatValue];
  76. NSString *levelBg = [barrageAttachment.gradeInfo objectForKey:@"img2"];
  77. CGFloat levelBgWidth = [[barrageAttachment.gradeInfo objectForKey:@"icon1_width"] floatValue];
  78. [youpaiplevelView youpaifreloadWithIcon:levelIcon iconWidth:levelIconWidth bgImg:levelBg bgImgWidth:levelBgWidth levelName:levelName level:level];
  79. [youpaiplevelView mas_makeConstraints:^(MASConstraintMaker *make) {
  80. make.left.equalTo(youpaipboardImgV.mas_right).offset(5.0f);
  81. make.centerY.equalTo(bgV);
  82. make.size.mas_offset(youpaiplevelView.mj_size);
  83. }];
  84. totalWidth += youpaiplevelView.mj_w + 5.0f;
  85. UILabel *contentL = [[UILabel alloc] init];
  86. contentL.font = LCFont(13.0f);
  87. contentL.textColor = HexColorFromRGB(0xFFDD8D);
  88. [barrageView addSubview:contentL];
  89. [contentL mas_makeConstraints:^(MASConstraintMaker *make) {
  90. make.left.offset(totalWidth);
  91. make.top.bottom.offset(0.0f);
  92. make.right.offset(-7.0f);
  93. }];
  94. if (barrageAttachment.userInfo != nil && [barrageAttachment.userInfo.allKeys containsObject:@"nickname"]) {
  95. NSString *nickname = [barrageAttachment.userInfo objectForKey:@"nickname"];
  96. contentL.text = [NSString stringWithFormat:@"%@ 来了!",nickname];
  97. }
  98. NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithObject:LCFont(13.5f) forKey:NSFontAttributeName];
  99. CGSize size = [contentL.text boundingRectWithSize:CGSizeMake(MAXFLOAT, 0.0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size;
  100. totalWidth = totalWidth + size.width + 7.0f;
  101. NSInteger heigth = KScreenHeight / 2;
  102. CGFloat y = arc4random() % heigth + heigth - 29.0f - SafeHeight;
  103. bgV.frame = CGRectMake(0.0f, y, totalWidth, 29.0f);
  104. [barrageView.layer addSublayer:[LCTools getGradientLayerWithSize:bgV.mj_size twoColors:@[[HexColorFromRGB(0xC55700) colorWithAlphaComponent:0.3f],[HexColorFromRGB(0xC55700) colorWithAlphaComponent:0.0f]] gradientType:GradientLeftToRight]];
  105. [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerBottomLeft View:bgV size:CGSizeMake(14.5f, 14.5f)];
  106. return bgV;
  107. }
  108. @end