环信代码分析笔记2
2015-11-23 14:06
357 查看
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];
}
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.消息模型设计:文字语音,图片。发送接收者
{
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];
}
[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;
}
相关文章推荐
- spring框架学习(一)
- python codeforces 322 div2 C
- JAVA 3DES加密解密
- Java - 文件(IO流)
- Mac 环境下配置opencv(Eclipse)
- jar命令成功完成 java -jar 命令却提示“没有主清单属性”!
- Java - 注解 (Annotation)
- Java 反射
- 编程基础知识之第一个Go程序
- Java中thread的join方法
- c++学习(函数模板, 类模板)<2>
- 代码重构
- Java - 泛型 ( Generic )
- Java数据类型和MySql数据类型对应表
- Spring4 IOC详解
- Python问题汇总
- 日志-java
- PYTHON之全局变量
- windows安装和配置JDK
- Java - 集合