服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - IOS - IOS实现聊天界面底部菜单栏效果

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

2021-03-27 17:11iOS开发网 IOS

本文给大家分享的是放boss直聘当中的聊天信息界面,主要思路是约束动画,实现代码比较简单,下面小编通过本文给大家分享IOS实现聊天界面底部菜单栏效果,需要的的朋友参考下吧

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

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

 

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

。h文件:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#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文件:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#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

测试代码:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
-(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实现聊天界面底部菜单栏效果,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对服务器之家网站的支持!

延伸 · 阅读

精彩推荐
  • IOSiOS 雷达效果实例详解

    iOS 雷达效果实例详解

    这篇文章主要介绍了iOS 雷达效果实例详解的相关资料,需要的朋友可以参考下...

    SimpleWorld11022021-01-28
  • IOSIOS开发之字典转字符串的实例详解

    IOS开发之字典转字符串的实例详解

    这篇文章主要介绍了IOS开发之字典转字符串的实例详解的相关资料,希望通过本文能帮助到大家,让大家掌握这样的方法,需要的朋友可以参考下...

    苦练内功5832021-04-01
  • IOS关于iOS自适应cell行高的那些事儿

    关于iOS自适应cell行高的那些事儿

    这篇文章主要给大家介绍了关于iOS自适应cell行高的那些事儿,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的...

    daisy6092021-05-17
  • IOSiOS布局渲染之UIView方法的调用时机详解

    iOS布局渲染之UIView方法的调用时机详解

    在你刚开始开发 iOS 应用时,最难避免或者是调试的就是和布局相关的问题,下面这篇文章主要给大家介绍了关于iOS布局渲染之UIView方法调用时机的相关资料...

    windtersharp7642021-05-04
  • IOSiOS中tableview 两级cell的展开与收回的示例代码

    iOS中tableview 两级cell的展开与收回的示例代码

    本篇文章主要介绍了iOS中tableview 两级cell的展开与收回的示例代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧...

    J_Kang3862021-04-22
  • IOSIOS 屏幕适配方案实现缩放window的示例代码

    IOS 屏幕适配方案实现缩放window的示例代码

    这篇文章主要介绍了IOS 屏幕适配方案实现缩放window的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要...

    xiari5772021-06-01
  • IOSiOS通过逆向理解Block的内存模型

    iOS通过逆向理解Block的内存模型

    自从对 iOS 的逆向初窥门径后,我也经常通过它来分析一些比较大的应用,参考一下这些应用中某些功能的实现。这个探索的过程乐趣多多,不仅能满足自...

    Swiftyper12832021-03-03
  • IOS解析iOS开发中的FirstResponder第一响应对象

    解析iOS开发中的FirstResponder第一响应对象

    这篇文章主要介绍了解析iOS开发中的FirstResponder第一响应对象,包括View的FirstResponder的释放问题,需要的朋友可以参考下...

    一片枫叶4662020-12-25