/*動畫
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];
}