自定义菜单

更新时间: 2025/05/29 15:56:13

本文介绍如何在 iOS 平台上使用网易会议组件 NEMeetingKit 进行菜单定制。

功能介绍

NEMeetingKit 支持通过 NEMeetingOptions 对会议界面中的菜单项进行自定义,包括工具栏菜单、更多菜单和成员操作菜单。

菜单的自定义包括修改文本、定制图标、菜单排序、菜单新增与删除等操作。

菜单类型分为两种:

  • 单状态菜单:只有一个固定状态,单击后执行相应操作(例如:打开设置)。
  • 多状态菜单:有多个状态,单击后可在不同状态间切换(例如:麦克风开/关、摄像头开/关)。

自定义工具栏菜单

工具栏菜单位于会议界面底部和顶部的主要控制区域。

image.png

示例代码

Objective-C// 创建工具栏菜单 builder
- (NEMeetingMenuItem *)inviteMenuItem {
    NESingleStateMenuItem *item = [[NESingleStateMenuItem alloc] init];
    item.itemId = FIRST_INJECTED_MENU_ID;
    item.visibility = VISIBLE_ALWAYS;

    NEMenuItemInfo *info = [[NEMenuItemInfo alloc] init];
    info.text = @"Invite";
    info.icon = @"invitation_light";
    info.lightIcon = @"invitation_light";
    info.darkIcon = @"invitation_dark";
    item.singleStateItem = info;
    return item;
}

NSMutableArray<NEMeetingMenuItem *> *fullToolbarMenuItems = [NEMenuItems defaultToolbarMenuItems];
// 添加到工具栏菜单中
[fullToolbarMenuItems addObject:[self inviteMenuItem]];

// 配置入会选项对象
NEJoinMeetingOptions *meetingOptions = [[NEJoinMeetingOptions alloc] init];
// 设置到会议选项中
meetingOptions.fullToolbarMenuItems = fullToolbarMenuItems;
// 加入会议
// params 应包含会议 ID 等会议参数
[[[NEMeetingKit getInstance] getMeetingService] joinMeeting:params opts:meetingOptions callback:^(NSInteger resultCode, NSString *resultMsg, id result) {}];

自定义菜单 ID 应避免与 NEMenuID 中定义的内置菜单 ID 冲突。使用大于 100 的整数值作为自定义菜单 ID。如需修改或管理内置菜单,则应使用相应的内置菜单 ID 常量。

自定义更多菜单

更多菜单是指单击会议界面底部 更多 按钮后显示的菜单项。

image.png

示例代码

Objective-C// 创建更多菜单 builder
NSMutableArray<NEMeetingMenuItem *> *fullMoreMenuItems [NEMenuItems defaultMoreMenuItems];
[fullMoreMenuItems addObject:[self inviteMenuItem]];

// 配置入会选项对象
NEJoinMeetingOptions *meetingOptions = [[NEJoinMeetingOptions alloc] init];
// 设置到会议选项中
meetingOptions.fullMoreMenuItems = fullMoreMenuItems;
// 加入会议
[[[NEMeetingKit getInstance] getMeetingService] joinMeeting:params opts:meetingOptions callback:^(NSInteger resultCode, NSString *resultMsg, id result) {}];

自定义成员上下文菜单

成员上下文菜单是指单击 管理参会者 图表后在管理参会者的页面中,单击某个成员后弹出的操作菜单。

image.png

示例代码

Objective-C// 创建成员操作菜单列表,首先获取内置菜单项列表(如静音、移出会议等)
NSMutableArray<NEMeetingMenuItem *> *memberActionMenuItems [NEMenuItems defaultActionMenuItems];
[memberActionMenuItems addObject:[self inviteMenuItem]];

NEJoinMeetingOptions *meetingOptions = [[NEJoinMeetingOptions alloc] init];
// 设置到会议选项中
meetingOptions.memberActionMenuItems = memberActionMenuItems;
// 加入会议
[[[NEMeetingKit getInstance] getMeetingService] joinMeeting:params opts:meetingOptions callback:^(NSInteger resultCode, NSString *resultMsg, id result) {}];

主动更新自定义菜单

在会议过程中,可以调用 updateInjectedMenuItem 根据需要实时更新已添加的自定义菜单。

示例代码

Objective-C// 创建新菜单信息
NECheckableMenuItem *item = [[NECheckableMenuItem alloc] init];
item.itemId = itemId;
item.visibility = VISIBLE_ALWAYS;
NEMenuItemInfo *info = [[NEMenuItemInfo alloc] init];
info.text = [NSString stringWithFormat:@"%@未-%@", text, @(item.itemId)];
info.icon = @"checkbox_n";
item.uncheckStateItem = info;

info = [[NEMenuItemInfo alloc] init];
info.text = [NSString stringWithFormat:@"%@-%@", text, @(item.itemId)];
info.icon = @"checkbox_s";
item.checkedStateItem = info;
item.checked = checked;

// 更新相同菜单 ID 的菜单项
// callback 用于接收更新结果
[NEMeetingKit.getInstance.getMeetingService updateInjectedMenuItem:item callback:^(NSInteger resultCode, NSString *resultMsg, id resultData) {}];

监听菜单单击事件

要响应自定义菜单的单击事件,您需要设置菜单单击监听器。

示例代码

Objective-C// 创建菜单单击事件监听器
@interface NEMeetingProvider ()<NEMeetingOnInjectedMenuItemClickListener>
@end
@implementation NEMeetingProvider

#pragma mark - NEMeetingOnInjectedMenuItemClickListener
- (void)onInjectedMenuItemClick:(NEMenuClickInfo *)clickInfo
                    meetingInfo:(NEMeetingInfo *)meetingInfo
                stateController:(NEMenuStateController)stateController {
    if (clickInfo.itemId == FIRST_INJECTED_MENU_ID) {
        // clickInfo 包含点击相关信息
        // meetingInfo 包含会议相关信息
        // stateController 用于控制菜单状态是否切换,用于多状态菜单
    }
}

// 重要:设置菜单单击事件监听器,需要在加入会议前设置
// 如果在加入会议后设置,可能无法接收到菜单单击事件
[[NEMeetingKit getInstance].getMeetingService setOnInjectedMenuItemClickListener:self];

@end
此文档是否对你有帮助?
有帮助
去反馈
  • 功能介绍
  • 自定义工具栏菜单
  • 自定义更多菜单
  • 自定义成员上下文菜单
  • 主动更新自定义菜单
  • 监听菜单单击事件