给融云的输入框上方加个功能按钮,怎么整?

10 篇文章 0 订阅
8 篇文章 0 订阅

给输入框上方加个功能按钮,类似常用语或者抽奖啥的,是个挺普遍的需求,可惜遍寻文档(https://docs.rongcloud.cn/v4/)无果,只能靠自己了,咱们来看看怎么做吧。

首先,我们要先在聊天页面添加个属性,也就是需要功能按钮所在的 view

@property (nonatomic, strong) UIView *needAddView;

再就是需要重写 viewWillAppear 生命周期函数,添加这个 needAddView,设置 UI 布局,保证进入页面时,needAddView 可以正确显示

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    //初始化 needAddView,添加到 self.view 上,坐标 y = 输入框的 y 坐标 - needAddView 高度
    CGFloat needAddView_height = 50.f;
    CGFloat y = self.chatSessionInputBarControl.frame.origin.y - needAddView_height;
    self.needAddView = [[UIView alloc] initWithFrame:CGRectMake(0, y, self.conversationMessageCollectionView.frame.size.width, needAddView_height)];
    self.needAddView.backgroundColor = [UIColor blueColor];
    [self.view addSubview:self.needAddView];
    
    //设置消息内容 collectionView 的高度,要减去 needAddView 的高度,避免被遮挡。
    CGRect frame = self.conversationMessageCollectionView.frame;
    frame.size.height -= needAddView_height;
    self.conversationMessageCollectionView.frame = frame;
}

最后需要根据输入框的位置变化,对 UI 布局做改变

-(void)chatInputBar:(RCChatSessionInputBarControl *)chatInputBar shouldChangeFrame:(CGRect)frame {
    //切记要调用父类方法,保证 UI 布局显示正确
    [super chatInputBar:chatInputBar shouldChangeFrame:frame];
    
    //needAddView 的坐标 y = 输入框的 y 坐标 - needAddView 高度。回调方法中的 frame 是输入框改变后的值。
    CGRect viewFrame = self.needAddView.frame;
    viewFrame.origin.y = frame.origin.y - viewFrame.size.height;
    self.needAddView.frame = viewFrame;
    
    //设置消息内容 collectionView 的高度,要减去 needAddView 的高度,避免被遮挡。
    CGRect collectionViewFrame = self.conversationMessageCollectionView.frame;
    collectionViewFrame.size.height -= self.needAddView.frame.size.height;
    self.conversationMessageCollectionView.frame = collectionViewFrame;
    
    //重新设置消息内容 collectionView 的 ContentOffset,正常显示消息内容。
    if (self.conversationMessageCollectionView.contentSize.height > collectionViewFrame.size.height) {
        [self.conversationMessageCollectionView setContentOffset:CGPointMake(0, self.conversationMessageCollectionView.contentSize.height - collectionViewFrame.size.height) animated:NO];
    }
}

最后再提一句,如果有类似的功能需求实现不了的,可以去融云官网(https://www.rongcloud.cn/),登录后台提工单,他们会有专人给出解决方案。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值