YOUPAILZAudienceMenuView.m 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. //
  2. // YOUPAILZAudienceMenuView.m
  3. // TIANYAN
  4. //
  5. // Created by CY on 2021/5/24.
  6. // Copyright © 2021 leo. All rights reserved.
  7. //
  8. #import "YOUPAILZAudienceMenuView.h"
  9. @interface YOUPAILZAudienceMenuView ()
  10. @property (nonatomic, strong) UIView *youpaipsupView;
  11. @property (nonatomic, weak) UIScrollView *youpaipscrollView;
  12. @property (nonatomic, strong) NSMutableArray <UIImageView *>* youpaipimgVs;
  13. @end
  14. @implementation YOUPAILZAudienceMenuView
  15. - (instancetype)initWithSupView:(UIView *)view{
  16. if (self = [super init]) {
  17. _youpaipsupView = view;
  18. self.frame = _youpaipsupView.bounds;
  19. self.hidden = YES;
  20. [self youpaifinitUI];
  21. [_youpaipsupView addSubview:self];
  22. }
  23. return self;
  24. }
  25. - (void)youpaifinitUI{
  26. UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, self.mj_h - 116.0f - SafeHeight, self.mj_w, 116.0f + SafeHeight)];
  27. scrollView.backgroundColor = HexColorFromRGB(0x2A2935);
  28. [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerTopRight View:scrollView size:CGSizeMake(20.0f, 20.0f)];
  29. scrollView.showsVerticalScrollIndicator = NO;
  30. scrollView.showsHorizontalScrollIndicator = NO;
  31. [self addSubview:scrollView];
  32. self.youpaipscrollView = scrollView;
  33. for (NSInteger i = 0; i < self.arr.count; i ++) {
  34. NSDictionary *dict = self.arr[i];
  35. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  36. CGFloat width = (self.mj_w - 4.0f) / self.arr.count;
  37. btn.frame = CGRectMake(2.0f + i * width, 28.0f, width, 60.0f);
  38. btn.tag = i;
  39. [btn addTarget:self action:@selector(youpaifbtnClick:) forControlEvents:UIControlEventTouchUpInside];
  40. [scrollView addSubview:btn];
  41. UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake((width - 42.0f) / 2.0f, 0, 42.0f, 42.0f)];
  42. imageV.image = dict[@"image"];
  43. [btn addSubview:imageV];
  44. [self.youpaipimgVs addObject:imageV];
  45. UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, imageV.mj_h + 5.0f, btn.mj_w, btn.mj_h - (imageV.mj_h + 5.0f))];
  46. lab.font = LCFont(10.0f);
  47. lab.textColor = HexColorFromRGB(0xAAAAAA);
  48. lab.textAlignment = NSTextAlignmentCenter;
  49. lab.text = dict[@"title"];
  50. [btn addSubview:lab];
  51. }
  52. }
  53. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
  54. UITouch* touch = [touches anyObject];
  55. UIView* view = [touch view];
  56. if (view != self.youpaipscrollView) {
  57. [self youpaifhiddenAnimation];
  58. }
  59. }
  60. - (void)youpaifbtnClick:(UIButton *)sender{
  61. sender.selected = !sender.selected;
  62. NSDictionary *dict = self.arr[sender.tag];
  63. NSString *type = dict[@"type"];
  64. UIImage *image = sender.selected ? dict[@"selImage"] : dict[@"image"];
  65. UIImageView *imgV = self.youpaipimgVs[sender.tag];
  66. imgV.image = image;
  67. if ([type isEqual:@"remove_screen"]) {
  68. if (self.youpaiphideChatMessageBlock != nil) {
  69. self.youpaiphideChatMessageBlock();
  70. }
  71. }else if ([type isEqual:@"blacklist"]) {
  72. if (self.youpaipblocklistBlock != nil) {
  73. self.youpaipblocklistBlock();
  74. }
  75. }else if ([type isEqual:@"report"]) {
  76. if (self.youpaipreportBlock != nil) {
  77. self.youpaipreportBlock();
  78. }
  79. }else if ([type isEqual:@"voice"]) {
  80. if (self.youpaipcloseVoiceBlock != nil) {
  81. self.youpaipcloseVoiceBlock(sender.selected);
  82. }
  83. }else if ([type isEqual:@"anchor_close"]) {
  84. if (self.youpaipcloseBlock != nil) {
  85. self.youpaipcloseBlock();
  86. }
  87. }
  88. [self youpaifhiddenAnimation];
  89. }
  90. - (void)youpaifshowAnimation{
  91. self.hidden = NO;
  92. self.youpaipscrollView.frame = CGRectMake(0, self.mj_h, self.mj_w, 116.0f + SafeHeight);
  93. [UIView animateWithDuration:0.25f animations:^{
  94. self.youpaipscrollView.frame = CGRectMake(0, self.mj_h - 116.0f - SafeHeight, self.mj_w, 116.0f + SafeHeight);
  95. }];
  96. }
  97. - (void)youpaifhiddenAnimation{
  98. self.youpaipscrollView.frame = CGRectMake(0, self.mj_h - 116.0f - SafeHeight, self.mj_w, 116.0f + SafeHeight);
  99. [UIView animateWithDuration:0.25f animations:^{
  100. self.youpaipscrollView.frame = CGRectMake(0, self.mj_h, self.mj_w, 116.0f + SafeHeight);
  101. } completion:^(BOOL finished) {
  102. if (finished) {
  103. self.hidden = YES;
  104. }
  105. }];
  106. }
  107. - (NSMutableArray<UIImageView *> *)youpaipimgVs{
  108. if (!_youpaipimgVs) {
  109. _youpaipimgVs = [[NSMutableArray alloc] init];
  110. }
  111. return _youpaipimgVs;
  112. }
  113. - (NSArray *)arr{
  114. return @[
  115. @{@"title":@"清屏",@"image":[UIImage imageNamed:@"vqu_images_L_live_remove_screen"],@"selImage":[UIImage imageNamed:@"vqu_images_L_live_remove_screen"],@"type":@"remove_screen"},
  116. @{@"title":@"拉黑",@"image":[UIImage imageNamed:@"vqu_images_L_live_blacklist"],@"selImage":[UIImage imageNamed:@"vqu_images_L_live_blacklist"],@"type":@"blacklist"},
  117. @{@"title":@"举报",@"image":[UIImage imageNamed:@"vqu_images_L_live_report"],@"selImage":[UIImage imageNamed:@"vqu_images_L_live_report"],@"type":@"report"},
  118. @{@"title":@"静音",@"image":[UIImage imageNamed:@"vqu_images_L_live_voice"],@"selImage":[UIImage imageNamed:@"vqu_images_L_live_voice_close"],@"type":@"voice"},
  119. // @{@"title":@"结束",@"image":[UIImage imageNamed:@"vqu_images_L_live_anchor_close"],@"selImage":[UIImage imageNamed:@"vqu_images_L_live_anchor_close"],@"type":@"anchor_close"},
  120. ];
  121. }
  122. @end