keyboard和 UITextFiled 之间的处理
2015-10-23 09:07
351 查看
//在 viewDidLoad注册通知监听keyboard 的弹出
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(KeyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
//键盘改变 frame 的时候会调用地方法;
- (void)KeyboardWillChangeFrame:(NSNotification *)noti {
NSLog(@"%@",noti);
//设置窗口的颜色;
self.view.window.backgroundColor = [UIColor whiteColor];
//取出键盘弹出用的时间;
CGFloat durtion = [noti.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
//键盘最后的 frame
CGRect keyFrame = [noti.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
//键盘在 view 上高度的变化;
CGFloat tranformH = keyFrame.origin.y - self.view.frame.size.height;
//改变时动画延时;
[UIView animateWithDuration:durtion animations:^{
self.view.transform = CGAffineTransformMakeTranslation(0, tranformH);
}];
}
//在 tableView 滑动的时候 keyboard 隐藏,此时要遵循 scrollerViewDelegate;(uitableVIewDetelate 也行)
#pragma scrollerViewDelegate;
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
//结束编辑, keyboard 回收;
[self.view endEditing:YES];
//[UIView animateWithDuration:0.25 animations:^{
// self.view.transform = CGAffineTransformMakeTranslation(0, 216);
// }];
}
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(KeyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
//键盘改变 frame 的时候会调用地方法;
- (void)KeyboardWillChangeFrame:(NSNotification *)noti {
NSLog(@"%@",noti);
//设置窗口的颜色;
self.view.window.backgroundColor = [UIColor whiteColor];
//取出键盘弹出用的时间;
CGFloat durtion = [noti.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
//键盘最后的 frame
CGRect keyFrame = [noti.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
//键盘在 view 上高度的变化;
CGFloat tranformH = keyFrame.origin.y - self.view.frame.size.height;
//改变时动画延时;
[UIView animateWithDuration:durtion animations:^{
self.view.transform = CGAffineTransformMakeTranslation(0, tranformH);
}];
}
//在 tableView 滑动的时候 keyboard 隐藏,此时要遵循 scrollerViewDelegate;(uitableVIewDetelate 也行)
#pragma scrollerViewDelegate;
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
//结束编辑, keyboard 回收;
[self.view endEditing:YES];
//[UIView animateWithDuration:0.25 animations:^{
// self.view.transform = CGAffineTransformMakeTranslation(0, 216);
// }];
}
相关文章推荐
- iOS 9 学习系列:UIKit Dynamics
- UI第二天总结
- UI第一天学习总结
- RMAN-07540: Cleanup is required for the VPC user schema
- QT GUI总结
- Qt探秘——谈ui文件的用法
- 关于easyui中的combogrid keyHanlder属性使用的问题(filter改进)
- Java学习笔记(二)GUI组件(1)
- 系统spt_values表--生成时间方便left join
- N-Queen Problem
- easyui-datagrid 两次请求
- 遍历Map key-value的两种方法
- MySQL EXPLAIN 独立子查询dependent subquery 优化示例
- UIButton 设置image ,title和setBackgroundImage
- ERPbuilder:连锁零售企业发展的新思路
- 从信息走向交易,B2Bbuilder能做些什么
- ERPbuilder:连锁零售企业发展的新思路
- Chapter 0.SymmetricDS快速入门指南( Quick Start Guide)
- web 应用 使用 shiro 安全框架 在 was7访问性能慢
- 详细整理:UITableView优化技巧