logo
当前页

自定义麦位

指定用户麦位

语聊房 UIKit(Live Audio Room Kit) 支持为语聊房中的角色设置指定麦位,主要接口如下:

  1. takeSeatIndexWhenJoining:当加入语聊房时(对于主持人和发言人),使用此选项自动设置用户所坐的麦位。
  2. hostSeatIndexes:仅用于设置 主持人 的特殊麦位(不允许发言人和观众就坐)。

自定义麦位布局

语聊房 UIKit 的布局方式,与行和对齐方式相关,如需自定义麦位布局,请参考以下说明:

  • ZegoLiveAudioRoomLayoutConfig:
    1. rowConfigs([ZegoLiveAudioRoomLayoutRowConfig]): 有多少行,以及每行的配置方式。
    1. rowSpacing(int): 每行的间距,必须 ≥ 0。
    • ZegoLiveAudioRoomLayoutRowConfig:
      1. count(int): 每行的麦位数,范围 [1 - 4]。
      2. seatSpacing(int): 每个麦位的水平间距,必须 ≥ 0(仅当对齐方式为 FLEX_STARTFLEX_ENDCENTER 时生效)。
      3. alignment(ZegoLiveAudioRoomLayoutAlignment): 为列设置的对齐方式。
    1. start: 将麦位尽可能靠近起始位置。
    2. end: 将麦位尽可能靠近结束位置。
    3. center: 将麦位尽可能靠中间位置。
    4. spaceBetween: 在麦位之间均匀分布剩余空间。
    5. spaceAround: 在麦位之间均匀分布剩余空间,并在第一个和最后一个麦位之前和之后分布一半的空间。
    6. spaceEvenly: 在麦位之间均匀分布剩余空间,并在第一个和最后一个麦位之前和之后分布相同的空间。
  • 六种 alignment 效果如下:

    以如下麦位设置为例,举例说明自定义设置的实现方式:

    1. 第一行的唯一麦位,设置为主持人的特殊麦位。
    1. 第二行和第三行的麦位数为 4,对齐方式为 spaceAround
  • Untitled
    class ViewController: UIViewController {
    
        let selfUserID: String = "userID"
        let selfUserName: String = "userName"
        let yourAppID: UInt32 = YourAppID
        let yourAppSign: String = "YourAppSign"
        let roomID: String = "YourRoomID"
    
        @IBAction func startLiveAudio(_ sender: Any) {
    
            // Modify your custom configurations here.
            let config: ZegoUIKitPrebuiltLiveAudioRoomConfig = ZegoUIKitPrebuiltLiveAudioRoomConfig.host()
            let layoutConfig: ZegoLiveAudioRoomLayoutConfig = ZegoLiveAudioRoomLayoutConfig()
            layoutConfig.rowSpecing = 5
            
            let rowConfig0: ZegoLiveAudioRoomLayoutRowConfig = ZegoLiveAudioRoomLayoutRowConfig()
            rowConfig0.count = 1
            rowConfig0.alignment = .center
            
            let rowConfig1: ZegoLiveAudioRoomLayoutRowConfig = ZegoLiveAudioRoomLayoutRowConfig()
            rowConfig1.count = 4
            rowConfig1.alignment = .spaceAround
            
            let rowConfig2: ZegoLiveAudioRoomLayoutRowConfig = ZegoLiveAudioRoomLayoutRowConfig()
            rowConfig2.count = 4
            rowConfig2.alignment = .spaceAround
            
            layoutConfig.rowConfigs = [rowConfig0,rowConfig1, rowConfig2]
            layoutConfig.rowSpecing = 0
            config.layoutConfig = layoutConfig
      
            let liveAudioVC = ZegoUIKitPrebuiltLiveAudioRoomVC.init(yourAppID, appSign: yourAppSign, userID: selfUserID, userName: selfUserName, roomID: roomID, config: config)
    
            liveAudioVC.modalPresentationStyle = .fullScreen
            self.present(liveAudioVC, animated: true, completion: nil)
        }
    }
    
    1
    Copied!

    自定义麦位的 UI

    默认情况下,麦位的用户界面会显示围绕用户头像的声浪。

    如果您对声浪样式不满意,或者想自定义前景和背景视图,请相应地使用seatConfig中的配置。

    隐藏声浪

    默认情况下,声浪会显示出来,如果要隐藏它,请使用showSoundWaveInAudioMode配置。

    showSoundWaveInAudioMode: 使用此选项来决定是否显示用户头像周围的声浪。默认情况下显示。

    以下是参考代码:

    Untitled
    class ViewController: UIViewController {
    
        let selfUserID: String = "userID"
        let selfUserName: String = "userName"
        let yourAppID: UInt32 = YourAppID
        let yourAppSign: String = "YourAppSign"
        let roomID: String = "YourRoomID"
    
        @IBAction func startLiveAudio(_ sender: Any) {
    
            // Modify your custom configurations here.
            let config: ZegoUIKitPrebuiltLiveAudioRoomConfig = ZegoUIKitPrebuiltLiveAudioRoomConfig.host()
            config.seatConfig.showSoundWaveInAudioMode = false
            let liveAudioVC = ZegoUIKitPrebuiltLiveAudioRoomVC.init(yourAppID, appSign: yourAppSign, userID: selfUserID, userName: selfUserName, roomID: roomID, config: config)
    
            liveAudioVC.modalPresentationStyle = .fullScreen
            self.present(liveAudioVC, animated: true, completion: nil)
        }
    }
    
    1
    Copied!

    自定义麦位的前景或背景视图

    要自定义麦位的背景视图,请使用以下属性:

    1. backgroundColor:使用此属性自定义背景颜色。
    2. backgroundImage:使用此属性自定义背景图片。
  • 要自定义用户麦位的前景视图,您需要声明 delegate 并实现 getSeatForegroundView 方法。

    以下是效果和参考代码的示例:

    Untitled
    class ViewController: UIViewController {
    
        let selfUserID: String = "userID"
        let selfUserName: String = "userName"
        let yourAppID: UInt32 = YourAppID
        let yourAppSign: String = "YourAppSign"
        let roomID: String = "YourRoomID"
    
        @IBAction func startLiveAudio(_ sender: Any) {
    
            // Modify your custom configurations here.
            let config: ZegoUIKitPrebuiltLiveAudioRoomConfig = ZegoUIKitPrebuiltLiveAudioRoomConfig.host()
            config.seatConfig.backgroudColor = <#Your backgroudColor#>
            config.seatConfig.backgroundImage = <#Your image#>
            let liveAudioVC = ZegoUIKitPrebuiltLiveAudioRoomVC.init(yourAppID, appSign: yourAppSign, userID: selfUserID, userName: selfUserName, roomID: roomID, config: config)
            liveAudioVC.delegate = self
            liveAudioVC.modalPresentationStyle = .fullScreen
            self.present(liveAudioVC, animated: true, completion: nil)
        }
    }
    
    extension ViewController : ZegoUIKitPrebuiltLiveAudioRoomVCDelegate {
        func getSeatForegroundView(_ userInfo: ZegoUIKitUser?, seatIndex: Int) -> UIView? {
            return YourCustomVideoForegroundView
        }
    }
    
    1
    Copied!

    Previous

    设置用户头像

    Next

    自定义背景