/*动画
1.监听键盘通知 UIKeyboardWillChangeFrameNotificationspa
2.实现监听通知的方法server
3.调整控制器View的位置rem
4.当控制器销毁的时候移除通知io
*/object
//监听键盘通知的方法select
/*方法
UIKeyboardAnimationCurveUserInfoKey = 7; 键盘弹出时候,执行动画的节奏im
UIKeyboardAnimationDurationUserInfoKey = "0.25"; 键盘动画执行的时间notification
UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {375, 258}}"; 键盘大小
UIKeyboardCenterBeginUserInfoKey = "NSPoint: {187.5, 796}"; 键盘开始的时候中心点位置
UIKeyboardCenterEndUserInfoKey = "NSPoint: {187.5, 538}"; 键盘结束的时候中心点位置
UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 667}, {375, 258}}"; 键盘开始时候的frame
UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 409}, {375, 258}}"; 键盘结束的时候的frame
// 1.监听键盘通知 UIKeyboardWillChangeFrameNotification
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrameNotification:) name:UIKeyboardWillChangeFrameNotification object:nil];
//2.实现监听通知的方法
- (void) keyboardWillChangeFrameNotification:(NSNotification *) notification
{
// NSLog(@"%@",notification.userInfo);
// 键盘开始位置
CGRect beginFrame = [notification.userInfo[UIKeyboardFrameBeginUserInfoKey] CGRectValue];
// 键盘结束的位置
CGRect endFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
// 取出控制器view的frame
CGRect viewFrame = self.view.frame;
// 调整控制器view的y坐标
viewFrame.origin.y += endFrame.origin.y - beginFrame.origin.y;
// 设置控制器的View的frame
self.view.frame = viewFrame;
}
//移除监听者
-(void)dealloc{
[[NSNotificationCenter defaultCenter]removeObserver:self];
}