YOUPAILZAnchorMenuView.m 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. //
  2. // YOUPAILZAnchorMenuView.m
  3. // TIANYAN
  4. //
  5. // Created by CY on 2021/5/21.
  6. // Copyright © 2021 leo. All rights reserved.
  7. //
  8. #import "YOUPAILZAnchorMenuView.h"
  9. static NSInteger const youpaipROWCOUNT = 4;
  10. @interface YOUPAILZAnchorMenuView ()
  11. @property (nonatomic, strong) UIView *youpaipsupView;
  12. @property (nonatomic, weak) UIScrollView *youpaipscrollView;
  13. @property (nonatomic, strong) NSMutableArray <UIImageView *>* youpaipimgVs;
  14. @end
  15. @implementation YOUPAILZAnchorMenuView
  16. - (instancetype)initWithSupView:(UIView *)view{
  17. if (self = [super init]) {
  18. _youpaipsupView = view;
  19. self.frame = _youpaipsupView.bounds;
  20. self.hidden = YES;
  21. [self youpaifinitUI];
  22. [_youpaipsupView addSubview:self];
  23. }
  24. return self;
  25. }
  26. - (void)youpaifinitUI{
  27. CGFloat totalHeight = [self youpaiftotalHeight];
  28. UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, self.mj_h - totalHeight - SafeHeight, self.mj_w, totalHeight + SafeHeight)];
  29. scrollView.backgroundColor = HexColorFromRGB(0x2A2935);
  30. [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerTopRight View:scrollView size:CGSizeMake(20.0f, 20.0f)];
  31. scrollView.showsVerticalScrollIndicator = NO;
  32. scrollView.showsHorizontalScrollIndicator = NO;
  33. [self addSubview:scrollView];
  34. self.youpaipscrollView = scrollView;
  35. CGFloat width = KScreenWidth / youpaipROWCOUNT;
  36. CGFloat height = 60.0f;
  37. for (NSInteger i = 0; i < self.arr.count; i ++) {
  38. NSDictionary *dict = self.arr[i];
  39. NSInteger row = i / youpaipROWCOUNT;
  40. NSInteger col = i % youpaipROWCOUNT;
  41. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  42. btn.frame = CGRectMake(col * width, 28.0f + row * height + row * 10.0f, width, height);
  43. btn.tag = i;
  44. [btn addTarget:self action:@selector(youpaifbtnClick:) forControlEvents:UIControlEventTouchUpInside];
  45. [scrollView addSubview:btn];
  46. UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake((width - 42.0f) / 2.0f, 0, 42.0f, 42.0f)];
  47. imageV.image = dict[@"image"];
  48. [btn addSubview:imageV];
  49. [self.youpaipimgVs addObject:imageV];
  50. UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, imageV.mj_h + 5.0f, btn.mj_w, btn.mj_h - (imageV.mj_h + 5.0f))];
  51. lab.font = LCFont(10.0f);
  52. lab.textColor = HexColorFromRGB(0xAAAAAA);
  53. lab.textAlignment = NSTextAlignmentCenter;
  54. lab.text = dict[@"title"];
  55. [btn addSubview:lab];
  56. }
  57. }
  58. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
  59. UITouch* touch = [touches anyObject];
  60. UIView* view = [touch view];
  61. if (view != self.youpaipscrollView) {
  62. [self youpaifhiddenAnimation];
  63. }
  64. }
  65. - (void)youpaifbtnClick:(UIButton *)sender{
  66. sender.selected = !sender.selected;
  67. NSDictionary *dict = self.arr[sender.tag];
  68. NSString *type = dict[@"type"];
  69. UIImage *image = sender.selected ? dict[@"selImage"] : dict[@"image"];
  70. UIImageView *imgV = self.youpaipimgVs[sender.tag];
  71. imgV.image = image;
  72. if ([type isEqual:@"remove_screen"]) {
  73. if (self.youpaiphideChatMessageBlock != nil) {
  74. self.youpaiphideChatMessageBlock();
  75. }
  76. }else if ([type isEqual:@"font_size"]) {
  77. if (self.youpaipreplaceChatMessageFontSizeBlock != nil) {
  78. self.youpaipreplaceChatMessageFontSizeBlock();
  79. }
  80. }else if ([type isEqual:@"voice"]) {
  81. if (self.youpaipcloseVoiceBlock != nil) {
  82. self.youpaipcloseVoiceBlock(sender.selected);
  83. }
  84. }else if ([type isEqual:@"change_camera"]) {
  85. if (self.youpaipchangeCameraBlock != nil) {
  86. self.youpaipchangeCameraBlock();
  87. }
  88. }else if ([type isEqual:@"anchor_beauty"]) {
  89. if (self.youpaipbeautyBlock != nil) {
  90. self.youpaipbeautyBlock();
  91. }
  92. }else if ([type isEqual:@"anchor_close"]) {
  93. if (self.youpaipcloseBlock != nil) {
  94. self.youpaipcloseBlock();
  95. }
  96. }else if ([type isEqual:@"bg_music"]) {
  97. if (self.showMusicBlock != nil) {
  98. self.showMusicBlock();
  99. }
  100. }else if ([type isEqual:@"member_manage"]) {
  101. if (self.showMemberManage != nil) {
  102. self.showMemberManage();
  103. }
  104. }
  105. [self youpaifhiddenAnimation];
  106. }
  107. - (void)youpaifshowAnimation{
  108. self.hidden = NO;
  109. CGFloat height = [self youpaiftotalHeight];
  110. self.youpaipscrollView.frame = CGRectMake(0, self.mj_h, self.mj_w, height + SafeHeight);
  111. [UIView animateWithDuration:0.25f animations:^{
  112. self.youpaipscrollView.frame = CGRectMake(0, self.mj_h - height - SafeHeight, self.mj_w, height + SafeHeight);
  113. }];
  114. }
  115. - (void)youpaifhiddenAnimation{
  116. CGFloat height = [self youpaiftotalHeight];
  117. self.youpaipscrollView.frame = CGRectMake(0, self.mj_h - height - SafeHeight, self.mj_w, height + SafeHeight);
  118. [UIView animateWithDuration:0.25f animations:^{
  119. self.youpaipscrollView.frame = CGRectMake(0, self.mj_h, self.mj_w, height + SafeHeight);
  120. } completion:^(BOOL finished) {
  121. if (finished) {
  122. self.hidden = YES;
  123. }
  124. }];
  125. }
  126. - (CGFloat)youpaiftotalHeight{
  127. NSInteger row = (self.arr.count + youpaipROWCOUNT - 1) / youpaipROWCOUNT;
  128. CGFloat height = 56.0f + (row * 60.0f) + ((row - 1) * 10.0f);
  129. return height;
  130. }
  131. - (NSMutableArray<UIImageView *> *)youpaipimgVs{
  132. if (!_youpaipimgVs) {
  133. _youpaipimgVs = [[NSMutableArray alloc] init];
  134. }
  135. return _youpaipimgVs;
  136. }
  137. - (NSArray *)arr{
  138. return @[
  139. @{@"title":@"美颜",@"image":[UIImage imageNamed:@"vqu_images_L_live_anchor_beauty"],@"selImage":[UIImage imageNamed:@"vqu_images_L_live_anchor_beauty"],@"type":@"anchor_beauty"},
  140. // @{@"title":@"背景音乐",@"image":[UIImage imageNamed:@"vqu_images_L_live_anchor_bg_music"],@"selImage":[UIImage imageNamed:@"vqu_images_L_live_anchor_bg_music"],@"type":@"bg_music"},
  141. @{@"title":@"清屏",@"image":[UIImage imageNamed:@"vqu_images_L_live_remove_screen"],@"selImage":[UIImage imageNamed:@"vqu_images_L_live_remove_screen"],@"type":@"remove_screen"},
  142. @{@"title":@"成员管理",@"image":[UIImage imageNamed:@"vqu_images_L_live_member_manage"],@"selImage":[UIImage imageNamed:@"vqu_images_L_live_member_manage"],@"type":@"member_manage"},
  143. @{@"title":@"镜头切换",@"image":[UIImage imageNamed:@"vqu_images_L_live_change_camera-1"],@"selImage":[UIImage imageNamed:@"vqu_images_L_live_change_camera-1"],@"type":@"change_camera"},
  144. @{@"title":@"静音",@"image":[UIImage imageNamed:@"vqu_images_L_live_voice"],@"selImage":[UIImage imageNamed:@"vqu_images_L_live_voice_close"],@"type":@"voice"},
  145. // @{@"title":@"大字幕",@"image":[UIImage imageNamed:@"vqu_images_L_live_font_size"],@"selImage":[UIImage imageNamed:@"vqu_images_L_live_font_size"],@"type":@"font_size"},
  146. ];
  147. }
  148. @end