全网整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:400-708-3566

IOS实现聊天界面底部菜单栏效果

-本安全出自个人小项目仿boss直聘当中的聊天信息界面:

实现的思路主要是:约束动画。

实现较简单,这里直接上代码:

。h文件:

#import <UIKit/UIKit.h> 
@protocol ShowMoreOptionListener <NSObject> 
@optional 
-(void) onChangListener; 
@end 
@class ScrollView; 
/** 
 底部菜单视图 
 */ 
@interface BottomMenuView : UIView 
@property(nonatomic,strong) UIView* showPartView;    //总是可见部分 
@property(nonatomic,strong) UIView* hiddenPartView;   //底部隐藏部分,需要点击显示部分才能显示出来 
@property(nonatomic,weak) id<ShowMoreOptionListener> delegate; //下面更多操作菜单的的状态代理器 
@property(nonatomic,strong) ScrollView* emojiPanel; 
-(void) buildOptionMenu; 
@end 

.m文件:

#import "BottomMenuView.h" 
#import "Masonry.h" 
#import "QuickWordsView.h" 
#import "ScrollView.h" 
#import "Constants.h" 
static const int QuickChat = 31; 
static const int Emoji = 32; 
static const int AddType = 33; 
static const int EmojiPanel = 34; 
static const int QuickChatPanel = 34; 
@implementation BottomMenuView 
-(instancetype) initWithFrame:(CGRect)frame{ 
  if(self = [super initWithFrame:frame]){} 
  return self; 
} 
-(void) buildOptionMenu{ 
  self.showPartView = [[UIView alloc] init]; 
  //self.showPartView.backgroundColor = [UIColor greenColor]; 
  [self addSubview:self.showPartView]; 
  //添加showPartView约束 
  [self.showPartView mas_makeConstraints:^(MASConstraintMaker *make) { 
    make.right.equalTo(self).offset(0); 
    make.top.equalTo(self); 
    make.left.equalTo(self); 
    make.height.mas_equalTo(40); 
  }]; 
  UIButton* showQuickWordsBtn = [[UIButton alloc] init]; 
  [showQuickWordsBtn setImage:[UIImage imageNamed:@"ic_chat_input_method"] forState:UIControlStateNormal]; 
  showQuickWordsBtn.imageView.contentMode = UIViewContentModeScaleAspectFit; 
  showQuickWordsBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; 
  showQuickWordsBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0); 
  showQuickWordsBtn.tag = QuickChat; 
  [showQuickWordsBtn addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside]; 
  [self.showPartView addSubview:showQuickWordsBtn]; 
  [showQuickWordsBtn mas_makeConstraints:^(MASConstraintMaker *make) { 
    make.leading.equalTo(self.showPartView).offset(0); 
    make.top.equalTo(self.showPartView); 
    make.size.mas_equalTo(CGSizeMake(90, 40)); 
  }]; 
  //中间编辑框 
  UITextView* editText = [[UITextView alloc] init]; 
  [self.showPartView addSubview:editText]; 
  [editText mas_makeConstraints:^(MASConstraintMaker *make) { 
    make.leading.equalTo(showQuickWordsBtn.mas_trailing).offset(-10); 
    make.centerY.equalTo(showQuickWordsBtn.mas_centerY); 
    make.height.mas_equalTo(37); 
    make.trailing.equalTo(self.showPartView).offset(-100); 
  }]; 
  //设置编辑框底部线 
  UIView* editTextbottomLine = [[UIView alloc] init]; 
  editTextbottomLine.backgroundColor = [UIColor blackColor]; 
  [self.showPartView addSubview:editTextbottomLine]; 
  [editTextbottomLine mas_makeConstraints:^(MASConstraintMaker *make) { 
    make.leading.equalTo(showQuickWordsBtn.mas_trailing).offset(-10); 
    make.top.equalTo(showQuickWordsBtn.mas_bottom); 
    make.height.mas_equalTo(1.0); 
    make.trailing.equalTo(self.showPartView).offset(-100); 
  }]; 
  //创建表情 
  UIButton* emojiBtn = [[UIButton alloc] init]; 
  [emojiBtn setImage:[UIImage imageNamed:@"ic_emoji.png"] forState:UIControlStateNormal]; 
  emojiBtn.imageView.contentMode = UIViewContentModeScaleAspectFit; 
  emojiBtn.tag = Emoji; 
  [emojiBtn addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside]; 
  [self addSubview:emojiBtn]; 
  [emojiBtn mas_makeConstraints:^(MASConstraintMaker *make) { 
    make.leading.equalTo(editText.mas_trailing).offset(5); 
    make.centerY.equalTo(self.showPartView.mas_centerY); 
    make.size.mas_equalTo(CGSizeMake(38, 38)); 
  }]; 
  //创建+btn 
  UIButton* addBtn = [[UIButton alloc] init]; 
  [addBtn setImage:[UIImage imageNamed:@"ic_gallery_add.png"] forState:UIControlStateNormal]; 
  addBtn.imageView.contentMode = UIViewContentModeScaleAspectFit; 
  addBtn.tag = AddType; 
  [addBtn addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside]; 
  [self addSubview:addBtn]; 
  [addBtn mas_makeConstraints:^(MASConstraintMaker *make) { 
    make.right.equalTo(self.showPartView).offset(-10); 
    make.centerY.equalTo(self.showPartView.mas_centerY); 
    make.size.mas_equalTo(CGSizeMake(38, 38)); 
  }]; 
  //设置永久显示底部线 
  UIView* bottomLine = [[UIView alloc] init]; 
  bottomLine.backgroundColor = [UIColor blackColor]; 
  [self.showPartView addSubview:bottomLine]; 
  [bottomLine mas_makeConstraints:^(MASConstraintMaker *make) { 
    make.leading.equalTo(showQuickWordsBtn); 
    make.top.equalTo(self.showPartView.mas_bottom).offset(5); 
    make.height.mas_equalTo(1.0); 
    make.trailing.equalTo(self.showPartView.mas_trailing); 
  }]; 
//  //下面开始处理隐藏部分,默认显示快捷消息 
//  QuickWordsView* quickWordsView = [[QuickWordsView alloc] init]; 
//  quickWordsView.separatorInset = UIEdgeInsetsMake(0,10,0,10); //top left right down 
//  quickWordsView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; //删除底部多余行,及分割线 
//  quickWordsView.tag = 100; 
//  [self addSubview:quickWordsView]; 
//  [quickWordsView mas_makeConstraints:^(MASConstraintMaker *make) { 
//    make.leading.equalTo(self); 
//    make.trailing.equalTo(self.mas_trailing); 
//    make.top.equalTo(self.mas_top).offset(47); 
//    make.height.mas_equalTo(210); 
//     
//  }]; 
  [self buildQuickChat]; 
} 
-(void)onClick:(UIButton*) button{ 
  switch(button.tag){ 
    case QuickChat:{ 
      if(self.delegate){ 
        [self.delegate onChangListener]; 
      } 
    }break; 
    case Emoji:{ 
    }break; 
    case AddType:{ 
    }break; 
  } 
} 
-(void) buildQuickChat{ 
  //下面开始处理隐藏部分,默认显示快捷消息 
  QuickWordsView* quickWordsView = [[QuickWordsView alloc] init]; 
  quickWordsView.separatorInset = UIEdgeInsetsMake(0,10,0,10); //top left right down 
  quickWordsView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; //删除底部多余行,及分割线 
  quickWordsView.tag = QuickChatPanel; 
  [self addSubview:quickWordsView]; 
  [quickWordsView mas_makeConstraints:^(MASConstraintMaker *make) { 
    make.leading.equalTo(self); 
    make.trailing.equalTo(self.mas_trailing); 
    make.top.equalTo(self.mas_top).offset(47); 
    make.height.mas_equalTo(210); 
  }]; 
} 
//-------------------kvo 实现观察主题 end---------------- 
@end 

测试代码:

-(void) testBottomMenu{ 
   self.menu = [[BottomMenuView alloc] init]; 
  self.menu.translatesAutoresizingMaskIntoConstraints = NO; 
  //self.menu.backgroundColor = [UIColor redColor]; 
  [self.menu buildOptionMenu]; 
  self.menu.delegate = self; 
  [self.view addSubview:self.menu]; 
  //使用约束来达到效果,下面开始添加约束 靠着底部 
  NSLayoutConstraint* alginBottom = [NSLayoutConstraint constraintWithItem:self.menu 
                                  attribute:NSLayoutAttributeBottom 
                                  relatedBy:NSLayoutRelationEqual 
                                   toItem:self.view 
                                  attribute:NSLayoutAttributeBottom 
                                 multiplier:1 
                                  constant:0.0]; 
  [self.view addConstraint:alginBottom]; 
  //添加高度 
  self.bottomHeightCons = [NSLayoutConstraint 
               constraintWithItem:self.menu 
               attribute:NSLayoutAttributeHeight 
               relatedBy:NSLayoutRelationEqual 
               toItem:nil 
               attribute:0 
               multiplier:1 
               constant:260]; 
  [self.menu addConstraint:self.bottomHeightCons]; 
  //添加右边约束 
  NSLayoutConstraint* rightMargin = [NSLayoutConstraint constraintWithItem:self.menu 
                                  attribute:NSLayoutAttributeRight 
                                  relatedBy:NSLayoutRelationEqual 
                                   toItem:self.view 
                                  attribute:NSLayoutAttributeRight 
                                 multiplier:1 
                                  constant:0.0]; 
  [self.view addConstraint:rightMargin]; 
  //添加左边约束 
  NSLayoutConstraint* leftMargin = [NSLayoutConstraint constraintWithItem:self.menu 
                                  attribute:NSLayoutAttributeLeft 
                                  relatedBy:NSLayoutRelationEqual 
                                   toItem:self.view 
                                  attribute:NSLayoutAttributeLeft 
                                 multiplier:1 
                                  constant:0.0]; 
  [self.view addConstraint:leftMargin]; 
} 
//更多操作按钮的协议监听接口 
-(void)onChangListener{ 
  //[self.view layoutIfNeeded]; 
  if(self.bottomHeightCons.constant == 40){ 
    self.bottomHeightCons.constant = 260; 
  }else{ 
    self.bottomHeightCons.constant = 40; 
  } 
  [UIView animateWithDuration:0.5 animations:^{ 
    [self.view layoutIfNeeded]; 
  }];    
} 

总结

以上所述是小编给大家介绍的IOS实现聊天界面底部菜单栏效果,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!


# ios  # 底部菜单栏  # Android仿IOS底部弹出对话框  # Android开发中实现IOS风格底部选择器(支持时间 日期 自定义)  # iOS实现只有底部边框线的输入框示例代码  # android底部弹出iOS7风格对话选项框(QQ对话框)--第三方开源之IOS_Dialog_Li  # 小编  # 分割线  # 在此  # 给大家  # 所述  # 给我留言  # 感谢大家  # 主要是  # 疑问请  # 有任何  # frame  # super  # initWithFrame  # CGRect  # return  # init  # backgroundColor  # UIColor  # alloc  # instancetype 


相关文章: 零服务器AI建站解决方案:快速部署与云端平台低成本实践  西安市网站制作公司,哪个相亲网站比较好?西安比较好的相亲网站?  深圳防火门网站制作公司,深圳中天明防火门怎么编码?  专业网站建设制作报价,网页设计制作要考什么证?  网站网页制作电话怎么打,怎样安装和使用钉钉软件免费打电话?  建站之星后台管理:高效配置与模板优化提升用户体验  建站之星体验版:智能建站系统+响应式设计,多端适配快速建站  文字头像制作网站推荐软件,醒图能自动配文字吗?  个人摄影网站制作流程,摄影爱好者都去什么网站?  浙江网站制作公司有哪些,浙江栢塑信息技术有限公司定制网站做的怎么样?  建站VPS配置与SEO优化指南:关键词排名提升策略  公司网站制作费用多少,为公司建立一个网站需要哪些费用?  洛阳网站制作公司有哪些,洛阳的招聘网站都有哪些?  制作网站的模板软件,网站怎么建设?  如何配置WinSCP新建站点的密钥验证步骤?  建站之星后台密码如何安全设置与找回?  专业网站制作企业网站,如何制作一个企业网站,建设网站的基本步骤有哪些?  广州网站建站公司选择指南:建站流程与SEO优化关键词解析  Python路径拼接规范_跨平台处理说明【指导】  建站之星在线客服如何快速接入解答?  设计网站制作公司有哪些,制作网页教程?  如何获取上海专业网站定制建站电话?  rsync同步时出现rsync: failed to set times on “xxxx”: Operation not permitted  贸易公司网站制作流程,出口贸易网站设计怎么做?  青岛网站建设如何选择本地服务器?  网站制作知乎推荐,想做自己的网站用什么工具比较好?  建站之星如何配置系统实现高效建站?  动图在线制作网站有哪些,滑动动图图集怎么做?  建站主机与服务器功能差异如何区分?  c# 服务器GC和工作站GC的区别和设置  为什么Go需要go mod文件_Go go mod文件作用说明  python的本地网站制作,如何创建本地站点?  广平建站公司哪家专业可靠?如何选择?  子杰智能建站系统|零代码开发与AI生成SEO优化指南  专业公司网站制作公司,用什么语言做企业网站比较好?  建站之星后台密码遗忘?如何快速找回?  详解ASP.NET 生成二维码实例(采用ThoughtWorks.QRCode和QrCode.Net两种方式)  整人网站在线制作软件,整蛊网站退不出去必须要打我是白痴才能出去?  如何用搬瓦工VPS快速搭建个人网站?  如何高效完成自助建站业务培训?  电视网站制作tvbox接口,云海电视怎样自定义添加电视源?  网站制作外包价格怎么算,招聘网站上写的“外包”是什么意思?  MySQL查询结果复制到新表的方法(更新、插入)  ppt在线制作免费网站推荐,有什么下载免费的ppt模板网站?  制作农业网站的软件,比较好的农业网站推荐一下?  如何在建站宝盒中设置产品搜索功能?  详解jQuery停止动画——stop()方法的使用  赚钱网站制作软件,建一个网站怎样才能赚钱?是如何盈利的?  建站主机选哪家性价比最高?  c# 在高并发场景下,委托和接口调用的性能对比 

您的项目需求

*请认真填写需求信息,我们会在24小时内与您取得联系。