- (void)registerForKeyboardNotifications {//使用NSNotificationCenter 鍵盤出現時[[NSNotificationCenter defaultCenter] addObserver:selfselector:@selector(keyboardWillShown:)name:UIKeyboardWillChangeFrameNotification object:nil];//使用NSNotificationCenter 鍵盤隐藏時[[NSNotificationCenter defaultCenter] addObserver:selfselector:@selector(keyboardWillBeHidden:)name:UIKeyboardWillHideNotification object:nil]; }//实现当键盘出现的时候计算键盘的高度大小。用于输入框显示位置 - (void)keyboardWillShown:(NSNotification*)aNotification {
NSDictionary *info = [notification userInfo];
CGFloat duration = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
NSValue *value = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
CGSize keyboardSize = [value CGRectValue].size;
//输入框位置动画加载
[UIView animateWithDuration:duration animations:^{
//do something
}];
}
//当键盘隐藏的时候- (void)keyboardWillBeHidden:(NSNotification*)aNotification{ //do something}