// // MORoomNormalMenuView.m // MiMoLive // // Created by SuperC on 2025/8/14. // #import "MORoomNormalMenuView.h" #import "MOShareMenuCell.h" #import "MOLiveMenuView.h" @interface MORoomNormalMenuView () @property (nonatomic, strong) UIView *bgView; @property (nonatomic, strong) UIButton *closeBtn; @property (nonatomic, strong) UICollectionView *collectionView; @end @implementation MORoomNormalMenuView - (instancetype)init { if (self = [super init] ) { [self setupUI]; } return self; } - (instancetype)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self){ [self setupUI]; } return self; } - (void)setupUI{ [self addSubview:self.bgView]; [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(self).offset(0); make.left.right.equalTo(self); make.height.equalTo(@(kScaleWidth(440.0))); }]; [self.bgView addSubview:self.collectionView]; [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.bgView).offset(12.0); make.right.equalTo(self.bgView).offset(-12.0); make.top.equalTo(self.bgView); make.bottom.equalTo(self.bgView); }]; [self addSubview:self.closeBtn]; [self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.left.right.equalTo(self); make.bottom.equalTo(self.bgView.mas_top); }]; } #pragma mark UICollectionViewDelegate,UICollectionViewDataSource - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ return self.titleArr.count; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ NSArray *modelArr = self.titleArr[section]; return modelArr.count; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ NSString *titleString = self.titleArr[indexPath.section][indexPath.row]; NSString *imgString = self.iconImgArr[indexPath.section][indexPath.row]; MOShareMenuCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:MOShareMenuCell_ID forIndexPath:indexPath]; cell.titleStr = titleString; cell.titleLab.text = titleString; if(self.linkMicModel){ [cell.iconBtn setBackgroundImage:[UIImage imageNamed:imgString] forState:UIControlStateNormal]; cell.titleLab.numberOfLines = 2; } else{ [cell.iconBtn setImage:[UIImage imageNamed:imgString] forState:UIControlStateNormal]; } cell.cellIndexPath = indexPath; if(self.titleColor){ cell.titleLab.textColor = self.titleColor; } WEAKSELF cell.iconClickBlock = ^(NSString * _Nonnull titleStr, NSIndexPath * _Nonnull cellIndexPath) { if(weakSelf.linkMicModel){ weakSelf.menuBtnClickAndLinkMicBlock ? weakSelf.menuBtnClickAndLinkMicBlock(titleStr, weakSelf.linkMicModel) : nil; } else{ weakSelf.menuBtnClickBlock ? weakSelf.menuBtnClickBlock(titleStr) : nil; [weakSelf dismissRoomNormalMenuView]; } }; return cell; } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ [collectionView deselectItemAtIndexPath:indexPath animated:YES]; } - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { if ([kind isEqualToString:UICollectionElementKindSectionHeader]) { MOLiveMenuCollectionReusableView *headView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"MOLiveMenuCollectionReusableView_ID" forIndexPath:indexPath]; headView.backgroundColor = [UIColor clearColor]; headView.titleLab.font = [MOTextTools semiboldFont:16.0]; headView.titleLab.textColor = kBaseTextColor_1; NSString *titleStr = self.tagArr[indexPath.section]; headView.titleLab.text = titleStr; [headView.titleLab mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(headView).offset(4.0); make.centerY.equalTo(headView); }]; return headView; } else{ UICollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"sectionFoot" forIndexPath:indexPath]; return view; } } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{ return CGSizeMake((SCREENWIDTH - 12.0 * 2), 52.0); } - (void)toReloadTheMenuView{ [self.collectionView reloadData]; } #pragma mark - Show - (void)showRoomNormalMenuView{ self.frame = CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT); CGFloat bgViewHeight = [self toUpdateTheBgViewHeight]; CGRect actionViewRect = self.bgView.frame; actionViewRect.origin.y = SCREENHEIGHT; self.bgView.frame = actionViewRect; WEAKSELF [UIView animateWithDuration:0.3 animations:^{ CGRect actionViewRect = weakSelf.bgView.frame; actionViewRect.origin.y = SCREENHEIGHT - bgViewHeight; weakSelf.bgView.frame = actionViewRect; }]; } - (CGFloat)toUpdateTheBgViewHeight{ CGFloat maxHeight = 440.0; CGFloat titleHeight = 52.0 * self.tagArr.count; CGFloat itemWidth = (SCREENWIDTH - 12.0 * 2 - 5.0) / 5.0; CGFloat itemHeight = 12.0 + itemWidth + 16.0 ; CGFloat allItemHeight = 0; for (NSArray *arr in self.titleArr) { CGFloat itemHeightTemp = itemHeight * ((arr.count + 4) / 5); allItemHeight = allItemHeight + itemHeightTemp; } allItemHeight = allItemHeight + titleHeight + 8.0 + HOME_KEY_HEIGHT; if (allItemHeight > maxHeight) { allItemHeight = maxHeight; } [self.bgView mas_updateConstraints:^(MASConstraintMaker *make) { make.height.equalTo(@(allItemHeight)); }]; return allItemHeight; } - (void)dismissRoomNormalMenuView{ self.viewDismissBlock ? self.viewDismissBlock() : nil; //完成下移动画 WEAKSELF [UIView animateWithDuration:0.3 animations:^ { CGRect actionSheetViewRect = weakSelf.bgView.frame; actionSheetViewRect.origin.y = SCREENHEIGHT; weakSelf.bgView.frame = actionSheetViewRect; } completion:^(BOOL finished) { [self removeFromSuperview]; }]; } #pragma mark - Lazy - (UIView *)bgView{ if(!_bgView){ _bgView = [[UIView alloc] init]; _bgView.backgroundColor = [MOTools colorWithHexString:@"#FFFFFF"]; _bgView.layer.cornerRadius = 16.0; _bgView.layer.masksToBounds = YES; _bgView.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner; } return _bgView; } - (UICollectionView *)collectionView{ if (!_collectionView) { UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init]; CGFloat width = (SCREENWIDTH - 12.0 * 2) / 5.0; CGFloat height = 12.0 + width + 16.0 ; flow.itemSize = CGSizeMake(width, height); flow.minimumLineSpacing = 0.0;//行间距 flow.minimumInteritemSpacing = 0.0;//列间距 flow.sectionInset = UIEdgeInsetsMake(9, 0, 0, 0); _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH, 70) collectionViewLayout:flow]; _collectionView.backgroundColor = [UIColor clearColor]; _collectionView.dataSource = self; _collectionView.delegate = self; [_collectionView registerNib:[UINib nibWithNibName:@"MOShareMenuCell" bundle:nil] forCellWithReuseIdentifier:MOShareMenuCell_ID]; [_collectionView registerClass:[MOLiveMenuCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"MOLiveMenuCollectionReusableView_ID"]; [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"sectionFoot"]; } return _collectionView; } - (UIButton *)closeBtn{ if(!_closeBtn){ _closeBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_closeBtn setTitle:@"" forState:UIControlStateNormal]; [_closeBtn addTarget:self action:@selector(closeBtnClickAction) forControlEvents:UIControlEventTouchUpInside]; } return _closeBtn; } - (void)closeBtnClickAction{ [self dismissRoomNormalMenuView]; } @end