view的frame高度根据键盘出现、消失改变
2016-07-14 17:05
495 查看
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor
yellowColor];
[[NSNotificationCenter
defaultCenter]addObserver:self
selector:@selector(action:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter
defaultCenter]addObserver:self
selector:@selector(action2:)
name:UIKeyboardWillHideNotification
object:nil];
}
//点击取消键盘
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent
*)event{
[self.textfield
resignFirstResponder];
}
//键盘出现
- (void)action:(NSNotification *)notification{
NSLog(@"%@",notification.userInfo);
CGRect rect = [notification.userInfo[@"UIKeyboardFrameEndUserInfoKey"]CGRectValue];
CGRect currentFrame =
self.view.frame;
currentFrame.origin.y -= rect.size.height;
self.view.frame = currentFrame;
}
//键盘消失
- (void)action2:(NSNotification *)notification{
NSLog(@"%@",notification.userInfo);
CGRect rect = [notification.userInfo[@"UIKeyboardFrameBeginUserInfoKey"]CGRectValue];
CGRect currentFrame =
self.view.frame;
currentFrame.origin.y += rect.size.height;
self.view.frame = currentFrame;
}
[super viewDidLoad];
self.view.backgroundColor = [UIColor
yellowColor];
[[NSNotificationCenter
defaultCenter]addObserver:self
selector:@selector(action:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter
defaultCenter]addObserver:self
selector:@selector(action2:)
name:UIKeyboardWillHideNotification
object:nil];
}
//点击取消键盘
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent
*)event{
[self.textfield
resignFirstResponder];
}
//键盘出现
- (void)action:(NSNotification *)notification{
NSLog(@"%@",notification.userInfo);
CGRect rect = [notification.userInfo[@"UIKeyboardFrameEndUserInfoKey"]CGRectValue];
CGRect currentFrame =
self.view.frame;
currentFrame.origin.y -= rect.size.height;
self.view.frame = currentFrame;
}
//键盘消失
- (void)action2:(NSNotification *)notification{
NSLog(@"%@",notification.userInfo);
CGRect rect = [notification.userInfo[@"UIKeyboardFrameBeginUserInfoKey"]CGRectValue];
CGRect currentFrame =
self.view.frame;
currentFrame.origin.y += rect.size.height;
self.view.frame = currentFrame;
}
相关文章推荐
- 利用JavaScript中的正则表达式实现常用输入框的验证
- github使用新手教程
- 【数据结构】顺序表
- Android IPC机制利用Messenger实现跨进程通信
- SpringBoot配置积累
- UE4里UI的使用方法
- 191Numberof1Bits
- 分享一个PHP代码的执行时间,精确到微秒级
- mybatis中#{}和${}传参的区别
- ubuntu 上安装tx1编译环境
- NOIP 2014 联合权值
- 兼容各个浏览器的图片上传预览
- 《Node.js开发加密货币》之二十二:自序
- zookeeper实践(一) 应用场景和能力
- about java techelogly
- 109. Convert Sorted List to Binary Search Tree
- Qt5 - 中文 - 常量中有换行符
- Activiti基础教程--08连线
- poj 2378(树形dp)
- 数码问题_纪中1433_暴力