环信代码分析笔记2
来源:互联网 发布:锐捷网络校园招聘笔试 编辑:程序博客网 时间:2024/06/09 21:24
1.续前一。getter的妙用。结构清晰。
[self.view addSubview:self.searchBar];
[self.view addSubview:self.tableView];
[self.tableView addSubview:self.slimeView];
2.检测网络状态变化 ,然后是否显示网络没连接状态。
(UIView *)networkStateView//getter.
{
if (_networkStateView == nil) {
_networkStateView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 44)];
_networkStateView.backgroundColor = [UIColor colorWithRed:255 / 255.0 green:199 / 255.0 blue:199 / 255.0 alpha:0.5];UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, (_networkStateView.frame.size.height - 20) / 2, 20, 20)];imageView.image = [UIImage imageNamed:@"messageSendFail"];[_networkStateView addSubview:imageView];UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(imageView.frame) + 5, 0, _networkStateView.frame.size.width - (CGRectGetMaxX(imageView.frame) + 15), _networkStateView.frame.size.height)];label.font = [UIFont systemFontOfSize:15.0];label.textColor = [UIColor grayColor];label.backgroundColor = [UIColor clearColor];label.text = NSLocalizedString(@"network.disconnection", @"Network disconnection");[_networkStateView addSubview:label];
}
return _networkStateView;
}- (void)networkChanged:(EMConnectionState)connectionState
{
if (connectionState == eEMConnectionDisconnected) {
_tableView.tableHeaderView = _networkStateView;
}
else{
_tableView.tableHeaderView = nil;
}
}
3.CELL里自定义IMAGE和LABEL的位置。
-(void)layoutSubviews{
[super layoutSubviews];
CGRect frame = self.imageView.frame;
// [self.imageView sd_setImageWithURL:_imageURL placeholderImage:_placeholderImage];
[self.imageView imageWithUsername:_name placeholderImage:_placeholderImage];
self.imageView.frame = CGRectMake(10, 7, 45, 45);
// self.textLabel.text = _name;
[self.textLabel setTextWithUsername:_name];
self.textLabel.frame = CGRectMake(65, 7, 175, 20);
}
4.消息模型设计:文字语音,图片。发送接收者
import
define KFIRETIME 20
@interface MessageModel : NSObject
{
BOOL _isPlaying;
}
@property (nonatomic) MessageBodyType type;
@property (nonatomic, readonly) MessageDeliveryState status;
@property (nonatomic) BOOL isSender; //是否是发送者
@property (nonatomic) BOOL isRead; //是否已读
@property (nonatomic) EMMessageType messageType; // 消息类型(单聊,群里,聊天室)
@property (nonatomic, strong, readonly) NSString *messageId;
@property (nonatomic, strong) NSURL *headImageURL;
@property (nonatomic, strong) NSString *nickName;
@property (nonatomic, strong) NSString *username;
//text
@property (nonatomic, strong) NSString *content;
//image
@property (nonatomic) CGSize size;
@property (nonatomic) CGSize thumbnailSize;
@property (nonatomic, strong) NSURL *imageRemoteURL;
@property (nonatomic, strong) NSURL *thumbnailRemoteURL;
@property (nonatomic, strong) UIImage *image;
@property (nonatomic, strong) UIImage *thumbnailImage;
//audio
@property (nonatomic, strong) NSString *localPath;
@property (nonatomic, strong) NSString *remotePath;
@property (nonatomic) NSInteger time;
@property (nonatomic, strong) EMChatVoice *chatVoice;
@property (nonatomic) BOOL isPlaying;
@property (nonatomic) BOOL isPlayed;
//location
@property (nonatomic, strong) NSString *address;
@property (nonatomic) double latitude;
@property (nonatomic) double longitude;
@property (nonatomic, strong)id messageBody;
@property (nonatomic, strong)EMMessage *message;
@end
5根据是否是发送者来定头像的位置。
.-(void)layoutSubviews
{
[super layoutSubviews];
CGRect frame = _headImageView.frame;frame.origin.x = _messageModel.isSender ? (self.bounds.size.width - _headImageView.frame.size.width - HEAD_PADDING) : HEAD_PADDING;_headImageView.frame = frame;[_nameLabel sizeToFit];frame = _nameLabel.frame;frame.origin.x = HEAD_PADDING * 2 + CGRectGetWidth(_headImageView.frame) + NAME_LABEL_PADDING;frame.origin.y = CGRectGetMinY(_headImageView.frame);frame.size.width = NAME_LABEL_WIDTH;_nameLabel.frame = frame;
}
- 环信代码分析笔记2
- 环信代码分析笔记1
- Mahout笔记--代码分析2
- 微信公众平台开发2:示例代码分析
- phpcms v9 代码分析笔记2
- Sipdroid信令代码结构分析
- 微信开发四----实例代码分析
- Mahout笔记--代码分析
- HelloRN代码分析笔记
- freeswitch代码分析笔记
- 代码笔记 | 网站微信登录
- 代码笔记 | 微信红包算法
- 环信笔记
- 环信笔记
- TQ2440启动代码分析笔记
- XGBoost代码走读分析笔记
- kvm分析笔记(1):代码结构分析
- [hyddd安全性测试笔记2]浅淡静态代码分析工具
- getReadableDatebase() 和getwriteableDatebase()
- spring框架学习(二)依赖注入
- 农商行信息化建设过程中存在哪些问题?
- Kibana User Guide [4.2] » Visualize » Vertical Bar Charts
- 动态调试pr_debug
- 环信代码分析笔记2
- MySQL索引背后的数据结构及算法原理
- spring框架学习(三)junit单元测试
- 职业规划:人生一堂必修课
- 如何把运行期警告转移到编译期的几个小技巧
- Eclipse安装SVN插件教程
- Android Scroller详解
- 【黑马程序员】C语言基础-循环结构
- 程序:从标准输入读取几行输入,每行输入都要打印到标准输出上,前面要加上行号。