[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(transformView:) name:UIKeyboardWillChangeFrameNotification object:nil];//键盘的弹出
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
//键盘的消失
//弹出键盘UIView
-(void)transformView:(NSNotification*)aNSNotification{
//获取键盘弹出前的Rect
NSValue*keyBoardBeginBounds=[[aNSNotification userInfo]objectForKey:UIKeyboardFrameBeginUserInfoKey];
CGRect beginRect=[keyBoardBeginBounds CGRectValue];
//获取键盘弹出后的Rect
NSValue*keyBoardEndBounds=[[aNSNotification userInfo]objectForKey:UIKeyboardFrameEndUserInfoKey];
CGRect endRect=[keyBoardEndBounds CGRectValue];
//获取键盘位置变化前后纵坐标Y的变化值
CGFloat deltaY=endRect.origin.y-beginRect.origin.y;
NSLog(@"看看这个变化的Y值:%f",deltaY);
//在0.25s内完成self.view的Frame的变化,等于是给self.view添加一个向上移动deltaY的动画
[UIView animateWithDuration:0.25f animations:^{
self.popView.frame = CGRectMake(0, -50, kScreenWidth, kScreenHeight);
}];
}
//退出键盘UIView
-(void)keyboardWillHide:(NSNotification*)aNSNotification{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.25];
[UIView setAnimationCurve:7];
self.popView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
[UIView commitAnimations];
}
iOS 键盘弹出与回收,界面上移/下移
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 1.ios高性能编程 (1).内层 最小的内层平均值和峰值(2).耗电量 高效的算法和数据结构(3).初始化时...
- //1.在.h文件中 #import#define MaxTextViewHeight 80 //限制文字输入的高...