键盘设置
2015-12-25 15:07
429 查看
(void)viewDidLoad{
//监听通知中心
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
//设置做边距
self.inputView.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 8, 0)];
//一直显示
self.inputView.leftViewMode = UITextFieldViewModeAlways;
}
(void)keyboardDidChangeFrame:(NSNotification *)noti{
NSLog(@”——–%@”,noti.userInfo);
//改变window的背景颜色
self.view.window.backgroundColor = self.tableView.backgroundColor;
// 键盘退出的frame
CGRect frame = [noti.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
//键盘实时y
CGFloat keyY = frame.origin.y;
//屏幕的高度
CGFloat screenH = [[UIScreen mainScreen] bounds].size.height;
//动画时间
CGFloat keyDuration = [noti.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue];
//执行动画
[UIView animateWithDuration:keyDuration animations:^{
self.view.transform = CGAffineTransformMakeTranslation(0, keyY - screenH);
}];
}
//当tableview 滚动的时候 结束编辑事件 (退出键盘)
(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
[self.view endEditing:YES];
}
// UIKeyboardAnimationCurveUserInfoKey = 7; 动画曲线动画
// UIKeyboardAnimationDurationUserInfoKey = “0.25”; 动画时间
// UIKeyboardBoundsUserInfoKey = “NSRect: {{0, 0}, {320, 216}}”; 键盘bounds
// UIKeyboardCenterBeginUserInfoKey = “NSPoint: {160, 588}”; 开始键盘的居中位置
// UIKeyboardCenterEndUserInfoKey = “NSPoint: {160, 372}”;结束键盘的居中位置
// UIKeyboardFrameBeginUserInfoKey = “NSRect: {{0, 480}, {320, 216}}”; 键盘开始弹出的frame
// UIKeyboardFrameChangedByUserInteraction = 0; 键盘改变frame
// UIKeyboardFrameEndUserInfoKey = “NSRect: {{0, 264}, {320, 216}}”; 退出键盘的frame
//监听通知中心
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
//设置做边距
self.inputView.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 8, 0)];
//一直显示
self.inputView.leftViewMode = UITextFieldViewModeAlways;
}
(void)keyboardDidChangeFrame:(NSNotification *)noti{
NSLog(@”——–%@”,noti.userInfo);
//改变window的背景颜色
self.view.window.backgroundColor = self.tableView.backgroundColor;
// 键盘退出的frame
CGRect frame = [noti.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
//键盘实时y
CGFloat keyY = frame.origin.y;
//屏幕的高度
CGFloat screenH = [[UIScreen mainScreen] bounds].size.height;
//动画时间
CGFloat keyDuration = [noti.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue];
//执行动画
[UIView animateWithDuration:keyDuration animations:^{
self.view.transform = CGAffineTransformMakeTranslation(0, keyY - screenH);
}];
}
//当tableview 滚动的时候 结束编辑事件 (退出键盘)
(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
[self.view endEditing:YES];
}
// UIKeyboardAnimationCurveUserInfoKey = 7; 动画曲线动画
// UIKeyboardAnimationDurationUserInfoKey = “0.25”; 动画时间
// UIKeyboardBoundsUserInfoKey = “NSRect: {{0, 0}, {320, 216}}”; 键盘bounds
// UIKeyboardCenterBeginUserInfoKey = “NSPoint: {160, 588}”; 开始键盘的居中位置
// UIKeyboardCenterEndUserInfoKey = “NSPoint: {160, 372}”;结束键盘的居中位置
// UIKeyboardFrameBeginUserInfoKey = “NSRect: {{0, 480}, {320, 216}}”; 键盘开始弹出的frame
// UIKeyboardFrameChangedByUserInteraction = 0; 键盘改变frame
// UIKeyboardFrameEndUserInfoKey = “NSRect: {{0, 264}, {320, 216}}”; 退出键盘的frame
相关文章推荐
- 如何找到w3wp与w3svc的对应关系
- 时间格式化
- maven Jetty plugin config
- Android Hybrid开发入门:原生Android与JS的交互
- Linux中在主机上实现对备机上目录及文件的操作的C代码实现
- freemark 使用 include 命令 出现空行的问题
- iOS给label添加下划线
- 微信发送消息中带网页连接
- 一段代码让你学会Python (借鉴)
- 关于阿里云ACE中JAVA平台的一些注意事项
- apache common包下的StringUtils的join方法
- 安装php
- 课程设计之学生成绩管理系统改良版
- javascript生成img标签的3种实现方法(对象、方法、html)
- Android中Service(服务)详解,四大组件之一:Service
- leetcode刷题日记——Same Tree
- Android APK反编译之源码
- 学习笔记(4)-社区发现评价指标
- VS2013 C++ Unicode环境下 BYTE 数组转CString的方法
- SQLite数据库的增删改查