YBLiveFucView.m 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //
  2. // YBLiveFucView.m
  3. // YBVideo
  4. //
  5. // Created by YB007 on 2019/12/1.
  6. // Copyright © 2019 cat. All rights reserved.
  7. //
  8. #import "YBLiveFucView.h"
  9. @interface YBLiveFucView()<UIGestureRecognizerDelegate>
  10. {
  11. NSMutableArray *_btn_m_array;
  12. UIView *_bgView;
  13. }
  14. @end
  15. @implementation YBLiveFucView
  16. +(instancetype)showBotFunViewWithTorch:(BOOL)isTorch Complete:(LiveFunBlcok)complete {
  17. YBLiveFucView *view = [[YBLiveFucView alloc]initWithFrame:CGRectMake(0, 0, _window_width, _window_height) torch:isTorch];
  18. view.backgroundColor = UIColor.clearColor;
  19. if (complete) {
  20. view.funEvent = ^(NSString *eventType) {
  21. complete(eventType);
  22. };
  23. }
  24. return view;
  25. }
  26. - (instancetype)initWithFrame:(CGRect)frame torch:(BOOL)isTorch {
  27. self = [super initWithFrame:frame];
  28. if (self) {
  29. [self createUI:isTorch];
  30. }
  31. return self;
  32. }
  33. -(void)createUI:(BOOL)isTorch {
  34. //不需要在这翻译,设置标题的时候翻译
  35. _btn_m_array = @[@"美颜",@"翻转",@"闪光灯",@"连麦",@"分享"].mutableCopy;
  36. //判断分享
  37. if ([[common share_type] count] == 0) {
  38. [_btn_m_array removeObject:@"分享"];
  39. }
  40. CGFloat bgView_W = _window_width - 20;
  41. int rowNum = 5;
  42. int lines = (int)_btn_m_array.count%rowNum == 0 ?((int)_btn_m_array.count/rowNum): ((int)_btn_m_array.count/rowNum+1);
  43. CGFloat btn_W = bgView_W/rowNum;
  44. CGFloat btnTopSpace = 5;
  45. _bgView = [[UIView alloc]init];
  46. _bgView.layer.cornerRadius = 5;
  47. _bgView.layer.masksToBounds = YES;
  48. _bgView.backgroundColor = [UIColor whiteColor];
  49. [self addSubview:_bgView];
  50. [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  51. make.width.mas_equalTo(bgView_W);
  52. make.centerX.equalTo(self);
  53. make.height.mas_equalTo((btnTopSpace+btn_W)*lines+btnTopSpace);
  54. make.bottom.equalTo(self.mas_bottom).offset(-ShowDiff-55);
  55. }];
  56. [self layoutIfNeeded];
  57. MASViewAttribute *leftAtt = _bgView.mas_left;
  58. MASViewAttribute *topAtt = _bgView.mas_top;
  59. for (int i=0; i<_btn_m_array.count; i++) {
  60. UIButton *btn = [UIButton buttonWithType:0];
  61. [btn addTarget:self action:@selector(doaction:) forControlEvents:UIControlEventTouchUpInside];
  62. [btn setTitleColor:[UIColor clearColor] forState:0];
  63. btn.tag = i + 1000;
  64. btn.titleLabel.font = SYS_Font(12);
  65. [btn setTitle:YZMsg(_btn_m_array[i]) forState:0];
  66. [btn setTitleColor:RGB_COLOR(@"#959697", 1) forState:0];
  67. [_bgView addSubview:btn];
  68. [btn mas_makeConstraints:^(MASConstraintMaker *make) {
  69. make.width.height.mas_equalTo(btn_W);
  70. make.left.equalTo(leftAtt);
  71. make.top.equalTo(topAtt).offset(btnTopSpace);
  72. }];
  73. leftAtt = btn.mas_right;
  74. if ((i+1)%rowNum == 0) {
  75. leftAtt = _bgView.mas_left;
  76. topAtt = btn.mas_bottom;
  77. }
  78. [_bgView layoutIfNeeded];
  79. [btn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"功能_%@",_btn_m_array[i]]] forState:0];
  80. if ([_btn_m_array[i] isEqual:@"闪光灯"]) {
  81. if (isTorch) {
  82. [btn setImage:[UIImage imageNamed:@"功能_闪光灯开"] forState:0];
  83. }else {
  84. [btn setImage:[UIImage imageNamed:@"功能_闪光灯关"] forState:0];
  85. }
  86. }
  87. btn = [PublicObj setUpImgDownText:btn];
  88. }
  89. UITapGestureRecognizer *tagGes = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismiss)];
  90. tagGes.delegate = self;
  91. [self addGestureRecognizer:tagGes];
  92. [[UIApplication sharedApplication].delegate.window addSubview:self];
  93. }
  94. -(void)doaction:(UIButton*)sender {
  95. [self dismiss];
  96. NSString *str = _btn_m_array[sender.tag - 1000];
  97. if (self.funEvent) {
  98. self.funEvent([NSString stringWithFormat:@"直播功能-%@",str]);
  99. }
  100. }
  101. - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
  102. if ([touch.view isDescendantOfView:_bgView]) {
  103. return NO;
  104. }
  105. return YES;
  106. }
  107. -(void)dismiss {
  108. if (self.funEvent) {
  109. self.funEvent(@"直播功能-取消");
  110. }
  111. [UIView animateWithDuration:0.4 animations:^{
  112. self.top = _bgView.height+60+ShowDiff;
  113. } completion:^(BOOL finished) {
  114. [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
  115. [self removeFromSuperview];
  116. }];
  117. }
  118. @end