iOS开发之 textView与键盘关系及 时间显示
2015-09-15 17:30
621 查看
效果展示: 这个适合做评论的时候使用
1、在创建senderButton 的时候,应该设置默认不可点击,即:senderButton。enable = no; 在调用senderButton 方法的尾部,也得设置senderButton。enable = no;在textView开始编辑的时候 ,senderButton。enable = yes;
2、通过通知
监测 键盘显示的状态
1⃣️、已经显示键盘的时候
UIKeyboardDidShowNotification
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyBoard:) name:UIKeyboardDidShowNotification object:nil];
2⃣️、键盘即将隐藏的时候 UIKeyboardWillHideNotification
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyBoard:) name:UIKeyboardWillHideNotification object:nil];
3⃣️、键盘显示状态的调用方法
- (void)keyBoard:(NSNotification *)not
{
NSDictionary *info = not.userInfo;//字典接收通知的信息
NSLog(@"%@",info);
//keyBoardRect 键盘的位置 全局变量
keyBoardRect = [info[UIKeyboardFrameEndUserInfoKey]CGRectValue];
bgView.frame = CGRectMake(0, CGRectGetMinY(keyBoardRect)-40, S_w, 40);
}
3、UITextView
发生改变的时候 调用的方法
(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
//
通过监测UITextView 输入的内容
得到它的内容高度 把内容的高度设置成 inputView
的高度 以及bgView的高度 ,并与键盘的高度关联起来
bgView.frame = CGRectMake(0, S_h-textView.contentSize.height-10-CGRectGetHeight(keyBoardRect), S_w, textView.contentSize.height+10);
inputView.frame = CGRectMake(50, 5, 200, textView.contentSize.height);
sendButton.frame = CGRectMake(CGRectGetMaxX(inputView.frame)+10, CGRectGetHeight(bgView.frame)-30-5, 80, 30);
return YES;//因返回值是一个BOOL值,所以得return一个BOOL值
4、显示时间
1⃣️、在点击button的同时,退出键盘
[inputView resignFirstResponder];
2⃣️、初始化时间并显示出来 NSDate
NSDate *curDate = [NSDate date];
NSLog(@"%@",[NSString stringWithFormat:@“%@",curDate]);
//显示的是系统自带的时间格式
3⃣️、自定义显示时间 即 设置时间格式 NSDateFormatter
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
//
设置 时间格式
formatter.dateFormat = @"yyyy-MM-dd hh:mm:ss E ";
NSString *time = [formatter stringFromDate:curDate];//
把curDate 按照时间格式的样式转换成
字符串
NSLog(@"%@",time);//NSDateFormatter
转换的时间
是转换成设备的时间
4⃣️指定根据那个key
进行分类显示 ascending: YES代表升序 NO
代表降序 NSSortDescriptor
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"time" ascending:NO];
NSMutableArray *sortDescriptorArr = [NSMutableArray arrayWithObjects:&sortDescriptor count:1];
[[allCotent sortedArrayUsingDescriptors:sortDescriptorArr]mutableCopy];
NSLog(@“%@",allCotent);
时间格式 基本了解
1、NSDate
时间格式
2、NSTimeInterval
时间间隔
基本单位 秒 S
3、NSDateFormatter
时间格式器 用于日期对象的格式化
或者字符串解析为日期对象
时间格式
日期格式如下:
y
年
M
年中的月份
D
当天是今年的第多少天
d
月份中的天数
F
月份中的周数
E
星期几
a Am/pm
H
一天中的小时数(0-23)
k
一天中的小时数(1-24)
K am/pm
中的小时数(0-11) Number 0
h am/pm
中的小时数(1-12) Number 12
m
小时中的分钟数 Number 30
s
分钟中的秒数 Number 55
S
毫秒数 Number 978
z
时区 General time zone Pacific Standard Time; PST; GMT-08:00
Z
时区 RFC 822 time zone -0800
时间戳
3、比较时间
(1)比较两个日期是不是相同的时间 isEqualToDate:
(2)获得较早
较晚的日期 earlierDate: laterDate:
(3)获得两个日期相隔多少秒
NSTimeInterval timeIntervalSinceDate:
1、在创建senderButton 的时候,应该设置默认不可点击,即:senderButton。enable = no; 在调用senderButton 方法的尾部,也得设置senderButton。enable = no;在textView开始编辑的时候 ,senderButton。enable = yes;
2、通过通知
监测 键盘显示的状态
1⃣️、已经显示键盘的时候
UIKeyboardDidShowNotification
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyBoard:) name:UIKeyboardDidShowNotification object:nil];
2⃣️、键盘即将隐藏的时候 UIKeyboardWillHideNotification
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyBoard:) name:UIKeyboardWillHideNotification object:nil];
3⃣️、键盘显示状态的调用方法
- (void)keyBoard:(NSNotification *)not
{
NSDictionary *info = not.userInfo;//字典接收通知的信息
NSLog(@"%@",info);
//keyBoardRect 键盘的位置 全局变量
keyBoardRect = [info[UIKeyboardFrameEndUserInfoKey]CGRectValue];
bgView.frame = CGRectMake(0, CGRectGetMinY(keyBoardRect)-40, S_w, 40);
}
3、UITextView
发生改变的时候 调用的方法
(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
//
通过监测UITextView 输入的内容
得到它的内容高度 把内容的高度设置成 inputView
的高度 以及bgView的高度 ,并与键盘的高度关联起来
bgView.frame = CGRectMake(0, S_h-textView.contentSize.height-10-CGRectGetHeight(keyBoardRect), S_w, textView.contentSize.height+10);
inputView.frame = CGRectMake(50, 5, 200, textView.contentSize.height);
sendButton.frame = CGRectMake(CGRectGetMaxX(inputView.frame)+10, CGRectGetHeight(bgView.frame)-30-5, 80, 30);
return YES;//因返回值是一个BOOL值,所以得return一个BOOL值
4、显示时间
1⃣️、在点击button的同时,退出键盘
[inputView resignFirstResponder];
2⃣️、初始化时间并显示出来 NSDate
NSDate *curDate = [NSDate date];
NSLog(@"%@",[NSString stringWithFormat:@“%@",curDate]);
//显示的是系统自带的时间格式
3⃣️、自定义显示时间 即 设置时间格式 NSDateFormatter
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
//
设置 时间格式
formatter.dateFormat = @"yyyy-MM-dd hh:mm:ss E ";
NSString *time = [formatter stringFromDate:curDate];//
把curDate 按照时间格式的样式转换成
字符串
NSLog(@"%@",time);//NSDateFormatter
转换的时间
是转换成设备的时间
4⃣️指定根据那个key
进行分类显示 ascending: YES代表升序 NO
代表降序 NSSortDescriptor
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"time" ascending:NO];
NSMutableArray *sortDescriptorArr = [NSMutableArray arrayWithObjects:&sortDescriptor count:1];
[[allCotent sortedArrayUsingDescriptors:sortDescriptorArr]mutableCopy];
NSLog(@“%@",allCotent);
时间格式 基本了解
1、NSDate
时间格式
2、NSTimeInterval
时间间隔
基本单位 秒 S
3、NSDateFormatter
时间格式器 用于日期对象的格式化
或者字符串解析为日期对象
时间格式
日期格式如下:
y
年
M
年中的月份
D
当天是今年的第多少天
d
月份中的天数
F
月份中的周数
E
星期几
a Am/pm
H
一天中的小时数(0-23)
k
一天中的小时数(1-24)
K am/pm
中的小时数(0-11) Number 0
h am/pm
中的小时数(1-12) Number 12
m
小时中的分钟数 Number 30
s
分钟中的秒数 Number 55
S
毫秒数 Number 978
z
时区 General time zone Pacific Standard Time; PST; GMT-08:00
Z
时区 RFC 822 time zone -0800
时间戳
3、比较时间
(1)比较两个日期是不是相同的时间 isEqualToDate:
(2)获得较早
较晚的日期 earlierDate: laterDate:
(3)获得两个日期相隔多少秒
NSTimeInterval timeIntervalSinceDate:
相关文章推荐
- iOS 开发之如何编辑tableView上的cell
- [原]IOS 7.1 以上企业及开发解决方案
- 开始iOS 7中自动布局教程(一)
- CocoaPods安装和使用
- ios utf8编码和解码
- iOS GCD使用指南
- 关于自己学习ios oc的学习笔记
- IOS开发中图片资源使用png还是jpg格式
- iOS 图片处理(截图,图片叠加(添加水印))
- iOS开发日记19-7.0之后的截屏方法
- Mac环境下svn的使用
- ios制作空白视频
- ios 指南针
- ios 开发 icon图标设置
- iOS开发之 分段选择控件 开关 滑杆
- iOS 调取本地相册/相机,剪裁图片进行头像上传
- iOS获取plist文件属性值的方法
- iOS开发之 手势
- iOS 不要使用tag传递TableViewCell的indexPath值
- ios 定位 航向检测