MORoomNormalMenuView.m 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. //
  2. // MORoomNormalMenuView.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2025/8/14.
  6. //
  7. #import "MORoomNormalMenuView.h"
  8. #import "MOShareMenuCell.h"
  9. #import "MOLiveMenuView.h"
  10. @interface MORoomNormalMenuView ()<UICollectionViewDelegate,UICollectionViewDataSource>
  11. @property (nonatomic, strong) UIView *bgView;
  12. @property (nonatomic, strong) UIButton *closeBtn;
  13. @property (nonatomic, strong) UICollectionView *collectionView;
  14. @end
  15. @implementation MORoomNormalMenuView
  16. - (instancetype)init {
  17. if (self = [super init] ) {
  18. [self setupUI];
  19. }
  20. return self;
  21. }
  22. - (instancetype)initWithFrame:(CGRect)frame{
  23. self = [super initWithFrame:frame];
  24. if (self){
  25. [self setupUI];
  26. }
  27. return self;
  28. }
  29. - (void)setupUI{
  30. [self addSubview:self.bgView];
  31. [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  32. make.bottom.equalTo(self).offset(0);
  33. make.left.right.equalTo(self);
  34. make.height.equalTo(@(kScaleWidth(440.0)));
  35. }];
  36. [self.bgView addSubview:self.collectionView];
  37. [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  38. make.left.equalTo(self.bgView).offset(12.0);
  39. make.right.equalTo(self.bgView).offset(-12.0);
  40. make.top.equalTo(self.bgView);
  41. make.bottom.equalTo(self.bgView);
  42. }];
  43. [self addSubview:self.closeBtn];
  44. [self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  45. make.top.left.right.equalTo(self);
  46. make.bottom.equalTo(self.bgView.mas_top);
  47. }];
  48. }
  49. #pragma mark UICollectionViewDelegate,UICollectionViewDataSource
  50. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  51. return self.titleArr.count;
  52. }
  53. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  54. NSArray *modelArr = self.titleArr[section];
  55. return modelArr.count;
  56. }
  57. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  58. NSString *titleString = self.titleArr[indexPath.section][indexPath.row];
  59. NSString *imgString = self.iconImgArr[indexPath.section][indexPath.row];
  60. MOShareMenuCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:MOShareMenuCell_ID forIndexPath:indexPath];
  61. cell.titleStr = titleString;
  62. cell.titleLab.text = titleString;
  63. if(self.linkMicModel){
  64. [cell.iconBtn setBackgroundImage:[UIImage imageNamed:imgString] forState:UIControlStateNormal];
  65. cell.titleLab.numberOfLines = 2;
  66. }
  67. else{
  68. [cell.iconBtn setImage:[UIImage imageNamed:imgString] forState:UIControlStateNormal];
  69. }
  70. cell.cellIndexPath = indexPath;
  71. if(self.titleColor){
  72. cell.titleLab.textColor = self.titleColor;
  73. }
  74. WEAKSELF
  75. cell.iconClickBlock = ^(NSString * _Nonnull titleStr, NSIndexPath * _Nonnull cellIndexPath) {
  76. if(weakSelf.linkMicModel){
  77. weakSelf.menuBtnClickAndLinkMicBlock ? weakSelf.menuBtnClickAndLinkMicBlock(titleStr, weakSelf.linkMicModel) : nil;
  78. }
  79. else{
  80. weakSelf.menuBtnClickBlock ? weakSelf.menuBtnClickBlock(titleStr) : nil;
  81. [weakSelf dismissRoomNormalMenuView];
  82. }
  83. };
  84. return cell;
  85. }
  86. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  87. [collectionView deselectItemAtIndexPath:indexPath animated:YES];
  88. }
  89. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
  90. {
  91. if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
  92. MOLiveMenuCollectionReusableView *headView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"MOLiveMenuCollectionReusableView_ID" forIndexPath:indexPath];
  93. headView.backgroundColor = [UIColor clearColor];
  94. headView.titleLab.font = [MOTextTools semiboldFont:16.0];
  95. headView.titleLab.textColor = kBaseTextColor_1;
  96. NSString *titleStr = self.tagArr[indexPath.section];
  97. headView.titleLab.text = titleStr;
  98. [headView.titleLab mas_remakeConstraints:^(MASConstraintMaker *make) {
  99. make.left.equalTo(headView).offset(4.0);
  100. make.centerY.equalTo(headView);
  101. }];
  102. return headView;
  103. }
  104. else{
  105. UICollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"sectionFoot" forIndexPath:indexPath];
  106. return view;
  107. }
  108. }
  109. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
  110. return CGSizeMake((SCREENWIDTH - 12.0 * 2), 52.0);
  111. }
  112. - (void)toReloadTheMenuView{
  113. [self.collectionView reloadData];
  114. }
  115. #pragma mark - Show
  116. - (void)showRoomNormalMenuView{
  117. self.frame = CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT);
  118. CGFloat bgViewHeight = [self toUpdateTheBgViewHeight];
  119. CGRect actionViewRect = self.bgView.frame;
  120. actionViewRect.origin.y = SCREENHEIGHT;
  121. self.bgView.frame = actionViewRect;
  122. WEAKSELF
  123. [UIView animateWithDuration:0.3 animations:^{
  124. CGRect actionViewRect = weakSelf.bgView.frame;
  125. actionViewRect.origin.y = SCREENHEIGHT - bgViewHeight;
  126. weakSelf.bgView.frame = actionViewRect;
  127. }];
  128. }
  129. - (CGFloat)toUpdateTheBgViewHeight{
  130. CGFloat maxHeight = 440.0;
  131. CGFloat titleHeight = 52.0 * self.tagArr.count;
  132. CGFloat itemWidth = (SCREENWIDTH - 12.0 * 2 - 5.0) / 5.0;
  133. CGFloat itemHeight = 12.0 + itemWidth + 16.0 ;
  134. CGFloat allItemHeight = 0;
  135. for (NSArray *arr in self.titleArr) {
  136. CGFloat itemHeightTemp = itemHeight * ((arr.count + 4) / 5);
  137. allItemHeight = allItemHeight + itemHeightTemp;
  138. }
  139. allItemHeight = allItemHeight + titleHeight + 8.0 + HOME_KEY_HEIGHT;
  140. if (allItemHeight > maxHeight) {
  141. allItemHeight = maxHeight;
  142. }
  143. [self.bgView mas_updateConstraints:^(MASConstraintMaker *make) {
  144. make.height.equalTo(@(allItemHeight));
  145. }];
  146. return allItemHeight;
  147. }
  148. - (void)dismissRoomNormalMenuView{
  149. self.viewDismissBlock ? self.viewDismissBlock() : nil;
  150. //完成下移动画
  151. WEAKSELF
  152. [UIView animateWithDuration:0.3 animations:^
  153. {
  154. CGRect actionSheetViewRect = weakSelf.bgView.frame;
  155. actionSheetViewRect.origin.y = SCREENHEIGHT;
  156. weakSelf.bgView.frame = actionSheetViewRect;
  157. } completion:^(BOOL finished)
  158. {
  159. [self removeFromSuperview];
  160. }];
  161. }
  162. #pragma mark - Lazy
  163. - (UIView *)bgView{
  164. if(!_bgView){
  165. _bgView = [[UIView alloc] init];
  166. _bgView.backgroundColor = [MOTools colorWithHexString:@"#FFFFFF"];
  167. _bgView.layer.cornerRadius = 16.0;
  168. _bgView.layer.masksToBounds = YES;
  169. _bgView.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;
  170. }
  171. return _bgView;
  172. }
  173. - (UICollectionView *)collectionView{
  174. if (!_collectionView)
  175. {
  176. UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];
  177. CGFloat width = (SCREENWIDTH - 12.0 * 2) / 5.0;
  178. CGFloat height = 12.0 + width + 16.0 ;
  179. flow.itemSize = CGSizeMake(width, height);
  180. flow.minimumLineSpacing = 0.0;//行间距
  181. flow.minimumInteritemSpacing = 0.0;//列间距
  182. flow.sectionInset = UIEdgeInsetsMake(9, 0, 0, 0);
  183. _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH, 70) collectionViewLayout:flow];
  184. _collectionView.backgroundColor = [UIColor clearColor];
  185. _collectionView.dataSource = self;
  186. _collectionView.delegate = self;
  187. [_collectionView registerNib:[UINib nibWithNibName:@"MOShareMenuCell" bundle:nil] forCellWithReuseIdentifier:MOShareMenuCell_ID];
  188. [_collectionView registerClass:[MOLiveMenuCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"MOLiveMenuCollectionReusableView_ID"];
  189. [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"sectionFoot"];
  190. }
  191. return _collectionView;
  192. }
  193. - (UIButton *)closeBtn{
  194. if(!_closeBtn){
  195. _closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  196. [_closeBtn setTitle:@"" forState:UIControlStateNormal];
  197. [_closeBtn addTarget:self action:@selector(closeBtnClickAction) forControlEvents:UIControlEventTouchUpInside];
  198. }
  199. return _closeBtn;
  200. }
  201. - (void)closeBtnClickAction{
  202. [self dismissRoomNormalMenuView];
  203. }
  204. @end