MONormalRightAlertView.m 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. //
  2. // MONormalRightAlertView.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2025/6/8.
  6. //
  7. #define MONormalRightMenuCellHeight 54.0
  8. #import "MONormalRightAlertView.h"
  9. #import "UIView+MOCornerRadius.h"
  10. #import "MONormalRightMenuCell.h"
  11. @interface MONormalRightAlertView ()<UITableViewDelegate,UITableViewDataSource>
  12. @property (weak, nonatomic) IBOutlet UIView *bgView;
  13. @property (weak, nonatomic) IBOutlet UITableView *tableView;
  14. @end
  15. @implementation MONormalRightAlertView
  16. + (instancetype)moNormalRightAlertView{
  17. return [[[NSBundle mainBundle] loadNibNamed:@"MONormalRightAlertView" owner:self options:nil] firstObject];
  18. }
  19. - (void)awakeFromNib{
  20. [super awakeFromNib];
  21. self.tableView.delegate = self;
  22. self.tableView.dataSource = self;
  23. self.tableView.rowHeight = MONormalRightMenuCellHeight;
  24. self.tableView.estimatedRowHeight = 0;
  25. self.tableView.estimatedSectionHeaderHeight = 0;
  26. self.tableView.estimatedSectionFooterHeight = 0;
  27. //iOS15适配
  28. if (@available(iOS 15.0, *))
  29. {
  30. self.tableView.sectionHeaderTopPadding = 0;
  31. }
  32. [self.tableView registerClass:[MONormalRightMenuCell class] forCellReuseIdentifier:MONormalRightMenuCell_ID];
  33. }
  34. - (void)setDataArr:(NSArray *)dataArr{
  35. _dataArr = dataArr;
  36. CGFloat theMenuHeight = dataArr.count * MONormalRightMenuCellHeight;
  37. self.menuViewHeight.constant = theMenuHeight;
  38. CGRect bgViewFrame = self.bgView.frame;
  39. bgViewFrame.size.height = theMenuHeight;
  40. self.bgView.frame = bgViewFrame;
  41. [self.bgView setCornerRadiusWithTopLeft:16.0 topRight:3.0 bottomRight:16.0 bottomLeft:16.0];
  42. [self.tableView reloadData];
  43. }
  44. - (IBAction)closeBtnClick:(id)sender {
  45. [self dismissVipMenuView];
  46. }
  47. #pragma mark - UITableViewDelegate,UITableViewDataSource
  48. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  49. return 1;
  50. }
  51. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  52. return self.dataArr.count;
  53. }
  54. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  55. NSDictionary *dict = self.dataArr[indexPath.row];
  56. MONormalRightMenuCell *cell = [tableView dequeueReusableCellWithIdentifier:MONormalRightMenuCell_ID];
  57. if (cell == nil){
  58. cell = [[MONormalRightMenuCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MONormalRightMenuCell_ID];
  59. }
  60. cell.cellModel = dict;
  61. return cell;
  62. }
  63. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  64. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  65. NSDictionary *dict = self.dataArr[indexPath.row];
  66. SEL action = NSSelectorFromString(dict[@"sel"]);
  67. __strong id target = self.target;
  68. if (target && [target respondsToSelector:action]) {
  69. [self dismissVipMenuView];
  70. [target performSelectorOnMainThread:action withObject:self waitUntilDone:YES];
  71. }
  72. }
  73. #pragma mark - Show
  74. - (void)showVipMenuView//界面显示动画
  75. {
  76. self.frame = CGRectMake(0.0, 0.0, SCREENWIDTH, SCREENHEIGHT);
  77. }
  78. - (void)dismissVipMenuView
  79. {
  80. [self removeFromSuperview];
  81. }
  82. @end