// // MOLiveMenuView.m // MiMoLive // // Created by SuperC on 2023/11/22. // #import "MOLiveMenuView.h" #import "MOShareMenuCell.h" @implementation MOLiveMenuCollectionReusableView - (UILabel *)titleLab{ if(!_titleLab){ _titleLab = [[UILabel alloc] init]; _titleLab.font = [MOTextTools poppinsSemiBoldFont:16.0]; _titleLab.textColor = kBaseTextColor_1; _titleLab.textAlignment = NSTextAlignmentLeft; [self addSubview:_titleLab]; [_titleLab mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self).offset(12.0); make.centerY.equalTo(self.mas_centerY); }]; } return _titleLab; } @end @interface MOLiveMenuView () @property (weak, nonatomic) IBOutlet UIView *bgView; @property (weak, nonatomic) IBOutlet NSLayoutConstraint *bgViewHeight; @property (weak, nonatomic) IBOutlet UICollectionView *collectionView; @property (nonatomic, strong) NSMutableArray *shareTitleArr; @property (nonatomic, strong) NSMutableArray *shareImgArr; @end @implementation MOLiveMenuView + (instancetype)moLiveMenuView{ return [[[NSBundle mainBundle] loadNibNamed:@"MOLiveMenuView" owner:self options:nil] firstObject]; } - (void)awakeFromNib{ [super awakeFromNib]; self.bgView.layer.cornerRadius = 16.0; self.bgView.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner; self.bgView.layer.masksToBounds = YES; self.bgViewHeight.constant = [MOLiveMenuView theViewHeight]; self.collectionView.contentInset = UIEdgeInsetsMake(9.0, 0, 0, 0); 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;//列间距 [self.collectionView setCollectionViewLayout:flow]; self.collectionView.delegate = self; self.collectionView.dataSource = self; [self.collectionView registerNib:[UINib nibWithNibName:@"MOShareMenuCell" bundle:nil] forCellWithReuseIdentifier:MOShareMenuCell_ID]; [self.collectionView registerClass:[MOLiveMenuCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"MOLiveMenuCollectionReusableView_ID"]; [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"sectionFoot"]; } + (CGFloat)theViewHeight{ CGFloat width = (SCREENWIDTH - 9.0 * 4 - 10.0 * 2) / 4.0; CGFloat height = width + 10.0; CGFloat viewHeight = height * 3.0 + 50.0 + 20.0; return viewHeight; } - (void)setIsCreatLive:(BOOL)isCreatLive{ _isCreatLive = isCreatLive; NSString *miniTitleStr; NSString *miniImgStr; NSString *giftTitleStr; NSString *giftImgStr; NSString *openResult = [[NSUserDefaults standardUserDefaults] valueForKey:@"kLiveSetMinimizeKey"]; if (openResult == nil || [openResult isEqualToString:@"open"]){ miniTitleStr = NSLocalString(@"mimo_2_live_menu_minimalkan"); miniImgStr = @"icon_live_minimize"; } else{ miniTitleStr = NSLocalString(@"mimo_2_live_menu_minimalkan_no"); miniImgStr = @"icon_live_minimize_no"; } NSString *giftResult = [[NSUserDefaults standardUserDefaults] valueForKey:kLiveSetHideGiftKey]; if (giftResult == nil || [giftResult isEqualToString:@"close"]){ giftTitleStr = NSLocalString(@"mimo_2_live_menu_hide_gift"); giftImgStr = @"icon_live_menu_gift"; } else{ giftTitleStr = NSLocalString(@"mimo_2_live_menu_hide_gift_no"); giftImgStr = @"icon_live_menu_gift_no"; } if(isCreatLive){ //Pk 连麦时的 功能按钮 if(self.isPkStatus){ self.shareTitleArr = @[@[NSLocalString(@"room_menu_data"),NSLocalString(@"room_menu_share"),NSLocalString(@"room_menu_message"),NSLocalString(@"room_menu_clear_screen"),giftTitleStr].mutableCopy,@[NSLocalString(@"mimo_boot_action_switch"),NSLocalString(@"room_type_mirror"),NSLocalString(@"room_type_resolution")]].mutableCopy; self.shareImgArr = @[@[@"room_menu_data",@"icon_live_menu_share",@"icon_live_menu_information",@"icon_live_menu_clean",giftImgStr].mutableCopy,@[@"icon_live_menu_turn_over",@"icon_live_menu_mirror",@"icon_live_menu_quality"]].mutableCopy; } else{ NSString *suspendTitle = (self.statusInfo.roomStatus.suspendExpire == 0) ? NSLocalString(@"room_menu_pause_live") : NSLocalString(@"room_menu_resume_live"); NSString *suspendImageStr = (self.statusInfo.roomStatus.suspendExpire == 0) ? @"icon_live_menu_pend" : @"icon_live_menu_live"; if(self.roomType == 1){ //非PK或连麦情况下的 - 菜单 self.shareTitleArr = @[@[NSLocalString(@"room_menu_data"),NSLocalString(@"room_menu_share"),NSLocalString(@"room_menu_message"),suspendTitle,NSLocalString(@"room_menu_clear_screen"),giftTitleStr].mutableCopy,@[NSLocalString(@"mimo_boot_action_switch"),NSLocalString(@"room_type_mirror"),NSLocalString(@"room_type_resolution")]].mutableCopy; self.shareImgArr = @[@[@"room_menu_data",@"icon_live_menu_share",@"icon_live_menu_information",suspendImageStr,@"icon_live_menu_clean",giftImgStr].mutableCopy,@[@"icon_live_menu_turn_over",@"icon_live_menu_mirror",@"icon_live_menu_quality"]].mutableCopy; } else{ //非PK或连麦情况下的 - 菜单 self.shareTitleArr = @[@[NSLocalString(@"room_menu_data"),NSLocalString(@"room_menu_share"),NSLocalString(@"room_menu_message"),suspendTitle,NSLocalString(@"room_menu_clear_screen"),giftTitleStr].mutableCopy,@[NSLocalString(@"mimo_boot_action_switch"),NSLocalString(@"room_type_mirror"),NSLocalString(@"room_type_resolution")]].mutableCopy; self.shareImgArr = @[@[@"room_menu_data",@"icon_live_menu_share",@"icon_live_menu_information",suspendImageStr,@"icon_live_menu_clean",giftImgStr].mutableCopy,@[@"icon_live_menu_turn_over",@"icon_live_menu_mirror",@"icon_live_menu_quality"]].mutableCopy; } } if(self.statusInfo.roomStatus.linkMics.count > 0){ //移除暂停直播 if([self.shareTitleArr[0] containsObject:NSLocalString(@"room_menu_pause_live")]){ [self.shareTitleArr[0] removeObject:NSLocalString(@"room_menu_pause_live")]; } if([self.shareImgArr[0] containsObject:@"icon_live_menu_pend"]){ [self.shareImgArr[0] removeObject:@"icon_live_menu_pend"]; } [self.shareTitleArr[0] addObject:NSLocalString(@"room_menu_room_set")]; [self.shareImgArr[0] addObject:@"c_m_btn_room_setting"]; } [self.collectionView reloadData]; } else{ if(self.isManager){ self.shareTitleArr = @[@[NSLocalString(@"room_menu_share"),@"Mall",NSLocalString(@"room_menu_message"),NSLocalString(@"room_menu_clear_screen"), @"Minimize"],@[@"LuckyWheel"]].mutableCopy; self.shareImgArr = @[@[@"icon_live_menu_share",@"icon_live_menu_mall",@"icon_live_menu_information",@"icon_live_menu_clean", @"icon_live_minimize"],@[@"icon_live_menu_lucky"]].mutableCopy; } else{ BOOL isShowWame = [MOTools toJudgeShowWame]; NSMutableArray *titleSecondTwoArr = @[NSLocalString(@"mimo_2_live_menu_pesan"),miniTitleStr,NSLocalString(@"mimo_2_live_menu_hide_chat"),giftTitleStr,NSLocalString(@"mimo_2_live_menu_gagikan")].mutableCopy; NSMutableArray *imgSecondTwoArr = @[@"icon_live_menu_information",miniImgStr,@"icon_live_menu_clean",giftImgStr,@"icon_live_menu_share"].mutableCopy; if(self.isWhiteList){ [titleSecondTwoArr addObject:NSLocalString(@"mimo_2_translate")]; [imgSecondTwoArr addObject:@"menu_icon_translation"]; } if(isShowWame){ NSString *wames = [MOTextAESTools smallSixTip]; self.shareTitleArr = @[@[NSLocalString(@"mimo_2_live_menu_angpao"),wames,NSLocalString(@"mimo_2_live_menu_mall")],titleSecondTwoArr].mutableCopy; self.shareImgArr = @[@[@"icon_live_menu_red",@"icon_live_menu_wame",@"icon_live_menu_mall"],imgSecondTwoArr].mutableCopy; } else{ self.shareTitleArr = @[@[NSLocalString(@"mimo_2_live_menu_angpao"),NSLocalString(@"mimo_2_live_menu_mall")],titleSecondTwoArr].mutableCopy; self.shareImgArr = @[@[@"icon_live_menu_red",@"icon_live_menu_mall"],imgSecondTwoArr].mutableCopy; } } [self.collectionView reloadData]; } } #pragma mark --UICollectionViewDatasource & delegate - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ return 2; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ NSArray *modelArr = self.shareTitleArr[section]; return modelArr.count; } -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ NSString *titleString = self.shareTitleArr[indexPath.section][indexPath.row]; NSString *imgString = self.shareImgArr[indexPath.section][indexPath.row]; MOShareMenuCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:MOShareMenuCell_ID forIndexPath:indexPath]; cell.titleStr = titleString; cell.titleLab.text = titleString; [cell.iconBtn setImage:[UIImage imageNamed:imgString] forState:UIControlStateNormal]; if(indexPath.section == 0){ cell.iconBtn.backgroundColor = [UIColor clearColor]; } else{ cell.iconBtn.backgroundColor = [MOTools colorWithHexString:@"#F6F7FB" alpha:1.0]; } cell.cellIndexPath = indexPath; WEAKSELF cell.iconClickBlock = ^(NSString * _Nonnull titleStr, NSIndexPath * _Nonnull cellIndexPath) { [weakSelf dismissMenuView]; weakSelf.menuBtnClickBlock ? weakSelf.menuBtnClickBlock(titleStr,cellIndexPath,weakSelf.isPkStatus) : nil; }; cell.switchChangeBlock = ^(NSString * _Nonnull titleStr, MOShareMenuCell * _Nonnull cell, UISwitch *switchView) { if (self.switchOpenBlock) { self.switchOpenBlock(titleStr, cell, switchView); } }; if ([titleString isEqualToString:@"Minimize"]) { cell.mySwitch.hidden = NO; cell.iconClickBlock = nil;//移除按钮点击block NSString *openResult = [[NSUserDefaults standardUserDefaults] valueForKey:@"kLiveSetMinimizeKey"]; if (openResult == nil || [openResult isEqualToString:@"open"]) { [cell.mySwitch setOn:YES]; cell.titleLab.text = NSLocalString(@"mimo_live_enable_minimize"); } else { [cell.mySwitch setOn:NO]; cell.titleLab.text = NSLocalString(@"mimo_live_disable_minimize"); } } else { cell.mySwitch.hidden = YES; cell.switchChangeBlock = nil;//移除开关点击block } //information 红点逻辑 if([titleString isEqualToString:NSLocalString(@"room_menu_message")] || [titleString isEqualToString:NSLocalString(@"mimo_2_live_menu_pesan")]){ NSInteger redNum = [MOSvgaSourceManage shareManager].theUserRedNum; if(redNum > 0){ cell.redNumLab.hidden = NO; cell.redNumLab.text = [NSString stringWithFormat:@"%zd",redNum]; CGFloat redNumNeedWidth = [MOTools getWidthWithString:[NSString stringWithFormat:@"%zd",redNum] font:[MOTextTools getTheFontWithSize:10.0 AndFontName:kNormalContentFontStr]] + 4.0; if(redNumNeedWidth < 12.0){ redNumNeedWidth = 12.0; } cell.redNumLabWidth.constant = redNumNeedWidth; } else{ cell.redNumLab.hidden = YES; cell.redNumLabWidth.constant = 12.0; } } else{ cell.redNumLab.hidden = YES; cell.redNumLabWidth.constant = 12.0; } 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; if(self.isCreatLive){ if(indexPath.section == 0){ headView.titleLab.text = NSLocalString(@"room_menu_live_tools"); } else{ headView.titleLab.text = NSLocalString(@"room_menu_base"); } } else{ if(indexPath.section == 0){ headView.titleLab.text = NSLocalString(@"mimo_2_live_menu_title_1"); } else{ headView.titleLab.text = NSLocalString(@"mimo_2_live_menu_title_2"); } } 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, 30.0); } - (IBAction)dismissBtnClick:(id)sender { [self dismissMenuView]; } - (void)showMenuView{ self.frame = CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT); 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 - [MOLiveMenuView theViewHeight]; weakSelf.bgView.frame = actionViewRect; }]; //不能滑动 SendNotification(@"MOShowLivePagesVCCannotScroll") } - (void)dismissMenuView{ //完成下移动画 WEAKSELF [UIView animateWithDuration:0.3 animations:^ { CGRect actionSheetViewRect = weakSelf.bgView.frame; actionSheetViewRect.origin.y = SCREENHEIGHT; weakSelf.bgView.frame = actionSheetViewRect; } completion:^(BOOL finished) { [self removeFromSuperview]; }]; if (self.dismissBlock) { self.dismissBlock(); } //可以滑动 SendNotification(@"MOShowLivePagesVCCanScroll") } #pragma mark - Lazy - (NSMutableArray *)shareTitleArr{ if(!_shareTitleArr){ _shareTitleArr = [NSMutableArray array]; } return _shareTitleArr; } - (NSMutableArray *)shareImgArr{ if(!_shareImgArr){ _shareImgArr = [NSMutableArray array]; } return _shareImgArr; } @end