YBLiveRoomAlertView.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. //
  2. // YBLiveRoomAlertView.m
  3. // YBVideo
  4. //
  5. // Created by YB007 on 2022/3/3.
  6. // Copyright © 2022 cat. All rights reserved.
  7. //
  8. #import "YBLiveRoomAlertView.h"
  9. @interface YBLiveRoomAlertView()<UIPickerViewDelegate,UIPickerViewDataSource>
  10. {
  11. NSInteger selRow;
  12. }
  13. /// 直播间警告
  14. @property(nonatomic,strong)NSDictionary *warningInfo;
  15. @property(nonatomic,strong)UIView *warningBgView;
  16. /// 直播间封禁选项
  17. @property(nonatomic,strong)NSArray *banOptionArray;
  18. @property(nonatomic,strong)UIView *banBgView;
  19. @property(nonatomic,strong)UIPickerView *banPicker;
  20. @end
  21. @implementation YBLiveRoomAlertView
  22. -(void)dissmissView {
  23. [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
  24. [self removeFromSuperview];
  25. }
  26. #pragma mark - 直播间警告
  27. +(YBLiveRoomAlertView *)showRoomWarning:(NSDictionary *)warningInfo;{
  28. YBLiveRoomAlertView *view = [[YBLiveRoomAlertView alloc]init];
  29. view.frame = CGRectMake(0, 0, _window_width, _window_height);
  30. view.warningInfo = warningInfo;
  31. //[[YBBaseAppDelegate sharedAppDelegate].topViewController.view addSubview:view];
  32. [[UIApplication sharedApplication].delegate.window addSubview:view];
  33. [view createWarningUI];
  34. return view;
  35. }
  36. -(void)createWarningUI {
  37. _warningBgView = [[UIView alloc]init];
  38. _warningBgView.backgroundColor = UIColor.whiteColor;
  39. _warningBgView.layer.cornerRadius = 10;
  40. _warningBgView.layer.masksToBounds = YES;
  41. [self addSubview:_warningBgView];
  42. [_warningBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.width.equalTo(self.mas_width).multipliedBy(0.75);
  44. make.centerX.centerY.equalTo(self);
  45. }];
  46. //
  47. UIImageView *topIV = [[UIImageView alloc]init];
  48. topIV.image = [UIImage imageNamed:@"房间-警告"];
  49. [_warningBgView addSubview:topIV];
  50. [topIV mas_makeConstraints:^(MASConstraintMaker *make) {
  51. make.width.height.mas_equalTo(40);
  52. make.top.equalTo(_warningBgView.mas_top).offset(10);
  53. make.centerX.equalTo(_warningBgView);
  54. }];
  55. ///
  56. UILabel *desL = [[UILabel alloc]init];
  57. desL.text = minstr([_warningInfo valueForKey:@"ct"]);
  58. desL.textColor = RGB_COLOR(@"#323232", 1);
  59. desL.font = SYS_Font(15);
  60. desL.textAlignment = NSTextAlignmentCenter;
  61. desL.numberOfLines = 0;
  62. [_warningBgView addSubview:desL];
  63. [desL mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.width.equalTo(_warningBgView.mas_width).offset(-30);
  65. make.centerX.equalTo(_warningBgView);
  66. make.top.equalTo(topIV.mas_bottom).offset(10);
  67. make.height.mas_greaterThanOrEqualTo(40);
  68. }];
  69. ///
  70. UIButton *knowBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  71. [knowBtn setTitle:YZMsg(@"知道了") forState:0];
  72. [knowBtn setTitleColor:RGB_COLOR(@"#ffffff", 1) forState:0];
  73. knowBtn.titleLabel.font = SYS_Font(15);
  74. knowBtn.backgroundColor = RGB_COLOR(@"#ff0000", 1);
  75. knowBtn.layer.cornerRadius = 5;
  76. knowBtn.layer.masksToBounds = YES;
  77. [knowBtn addTarget:self action:@selector(clickKnowBtn) forControlEvents:UIControlEventTouchUpInside];
  78. [_warningBgView addSubview:knowBtn];
  79. [knowBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  80. make.height.mas_equalTo(40);
  81. make.top.equalTo(desL.mas_bottom).offset(15);
  82. make.bottom.equalTo(_warningBgView.mas_bottom).offset(-15);
  83. make.width.equalTo(_warningBgView.mas_width).multipliedBy(0.8);
  84. make.centerX.equalTo(_warningBgView);
  85. }];
  86. }
  87. -(void)clickKnowBtn {
  88. [self dissmissView];
  89. }
  90. #pragma mark - 直播间封禁选项
  91. +(YBLiveRoomAlertView *)showBanOption:(NSArray *)banArray;{
  92. YBLiveRoomAlertView *view = [[YBLiveRoomAlertView alloc]init];
  93. view.frame = CGRectMake(0, 0, _window_width, _window_height);
  94. view.banOptionArray = banArray;
  95. [[YBBaseAppDelegate sharedAppDelegate].topViewController.view addSubview:view];
  96. [view createBanOptionUI];
  97. return view;
  98. }
  99. -(void)createBanOptionUI {
  100. // _banOptionArray = @[
  101. // @{@"type":@"1",@"title":@"30分钟"},
  102. // @{@"type":@"2",@"title":@"1天"},
  103. // @{@"type":@"3",@"title":@"7天"},
  104. // @{@"type":@"4",@"title":@"15天"},
  105. // @{@"type":@"5",@"title":@"30天"},
  106. // @{@"type":@"6",@"title":@"90天"},
  107. // @{@"type":@"7",@"title":@"180天"},
  108. // @{@"type":@"8",@"title":@"永久"},
  109. // ];
  110. //
  111. _banBgView = [[UIView alloc]init];
  112. _banBgView.backgroundColor = UIColor.whiteColor;
  113. _banBgView.layer.cornerRadius = 10;
  114. _banBgView.layer.masksToBounds = YES;
  115. [self addSubview:_banBgView];
  116. [_banBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  117. make.width.equalTo(self.mas_width).multipliedBy(0.75);
  118. make.centerX.centerY.equalTo(self);
  119. }];
  120. UILabel *titleL = [[UILabel alloc]init];
  121. titleL.text = YZMsg(@"请选择封禁时间");
  122. titleL.textColor = RGB_COLOR(@"#323232", 1);
  123. titleL.font = SYS_Font(15);
  124. titleL.textAlignment = NSTextAlignmentCenter;
  125. [_banBgView addSubview:titleL];
  126. [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
  127. make.width.equalTo(_banBgView.mas_width).offset(-30);
  128. make.centerX.equalTo(_banBgView);
  129. make.top.equalTo(_banBgView.mas_top).offset(0);
  130. make.height.mas_equalTo(50);
  131. }];
  132. _banPicker = [[UIPickerView alloc]initWithFrame:CGRectMake(0, 0, _window_width, 100)];
  133. _banPicker.backgroundColor = [UIColor whiteColor];
  134. _banPicker.delegate = self;
  135. _banPicker.dataSource = self;
  136. _banPicker.showsSelectionIndicator = YES;
  137. [_banPicker selectRow: 0 inComponent: 0 animated: YES];
  138. [_banBgView addSubview:_banPicker];
  139. [_banPicker mas_makeConstraints:^(MASConstraintMaker *make) {
  140. make.width.centerX.equalTo(_banBgView);
  141. make.top.equalTo(titleL.mas_bottom).offset(0);
  142. make.height.mas_equalTo(100);
  143. }];
  144. UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  145. [cancelBtn setTitle:YZMsg(@"取消") forState:0];
  146. cancelBtn.titleLabel.font = SYS_Font(13);
  147. [cancelBtn setTitleColor:RGB_COLOR(@"#ffffff", 1) forState:0];
  148. cancelBtn.layer.cornerRadius = 15;
  149. cancelBtn.layer.masksToBounds = YES;
  150. cancelBtn.backgroundColor = RGB_COLOR(@"#b3b3b3", 1);
  151. [cancelBtn addTarget:self action:@selector(clickCancelBtn) forControlEvents:UIControlEventTouchUpInside];
  152. [_banBgView addSubview:cancelBtn];
  153. [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  154. make.width.equalTo(_banBgView.mas_width).multipliedBy(0.3);
  155. make.centerX.equalTo(_banBgView.mas_centerX).multipliedBy(0.5);
  156. make.height.mas_equalTo(30);
  157. make.top.equalTo(_banPicker.mas_bottom).offset(10);
  158. make.bottom.equalTo(_banBgView).offset(-15);
  159. }];
  160. UIButton *sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  161. [sureBtn setTitle:YZMsg(@"确定") forState:0];
  162. sureBtn.titleLabel.font = SYS_Font(13);
  163. [sureBtn setTitleColor:RGB_COLOR(@"#ffffff", 1) forState:0];
  164. sureBtn.layer.cornerRadius = 15;
  165. sureBtn.layer.masksToBounds = YES;
  166. sureBtn.backgroundColor = Pink_Cor;
  167. [sureBtn addTarget:self action:@selector(clickSureBtnBtn) forControlEvents:UIControlEventTouchUpInside];
  168. [_banBgView addSubview:sureBtn];
  169. [sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  170. make.width.height.centerY.equalTo(cancelBtn);
  171. make.centerX.equalTo(_banBgView.mas_centerX).multipliedBy(1.5);
  172. }];
  173. }
  174. -(void)clickCancelBtn {
  175. [self dissmissView];
  176. }
  177. -(void)clickSureBtnBtn {
  178. int idx = (int)[_banPicker selectedRowInComponent:0];
  179. NSDictionary *selDic = _banOptionArray[idx];
  180. NSString *selId = minstr([selDic valueForKey:@"id"]);
  181. if (self.banEvent) {
  182. self.banEvent(selId);
  183. }
  184. }
  185. #pragma mark--- Picker Data Source Methods-----
  186. - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
  187. return 1;
  188. }
  189. - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
  190. return _banOptionArray.count;
  191. }
  192. - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
  193. return minstr([_banOptionArray[row] valueForKey:@"title"]);
  194. }
  195. - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
  196. selRow = row;
  197. [_banPicker reloadAllComponents];
  198. }
  199. - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
  200. for(UIView *speartorView in pickerView.subviews) {
  201. speartorView.backgroundColor = UIColor.clearColor;
  202. if (speartorView.frame.size.height < 80) {//找出当前的 View
  203. // 添加分割线 (判断只添加一次 滑动不断刷新)
  204. if (speartorView.subviews.count == 0){
  205. /*
  206. UIView *line = [self lineView];
  207. line.frame = CGRectMake(0, 0, speartorView.mj_w, 0.5);
  208. [speartorView addSubview:line];
  209. UIView *line2 = [self lineView];
  210. line2.frame = CGRectMake(0, speartorView.mj_h-1, speartorView.mj_w, 0.5);
  211. [speartorView addSubview:line2];
  212. */
  213. }
  214. speartorView.backgroundColor = [UIColor clearColor];
  215. }else{
  216. speartorView.backgroundColor = [UIColor clearColor];
  217. }
  218. }
  219. UILabel* pickerLabel = (UILabel*)view;
  220. if (!pickerLabel){
  221. pickerLabel = [[UILabel alloc] init];
  222. pickerLabel.adjustsFontSizeToFitWidth = YES;
  223. [pickerLabel setTextAlignment:NSTextAlignmentCenter];
  224. pickerLabel.backgroundColor = RGB_COLOR(@"#f3f3f3", 1);
  225. pickerLabel.font = [UIFont systemFontOfSize:15];
  226. }
  227. if (row == selRow) {
  228. pickerLabel.textColor = RGB_COLOR(@"#323232", 1);
  229. }
  230. pickerLabel.text=[self pickerView:pickerView titleForRow:row forComponent:component];
  231. return pickerLabel;
  232. }
  233. - (UIView *)lineView {
  234. UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _banPicker.width*0.8, 0.5)];
  235. line.backgroundColor = UIColor.clearColor;//RGB_COLOR(@"#DCDCDC", 1);
  236. return line;
  237. }
  238. @end