- (void)registerForKeyboardNotifications
{
//使用NSNotificationCenter 键盘弹出时
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShown:)
name:UIKeyboardWillChangeFrameNotification object:nil];
//使用NSNotificationCenter 键盘隐藏时
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillBeHidden:)
name:UIKeyboardWillHideNotification object:nil];
}
- (void)keyboardWillShown:(NSNotification*)aNotification
{
NSDictionary *info = [aNotification 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
{
NSDictionary *info = [aNotification userInfo];
CGFloat duration = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
[UIView animateWithDuration:duration animations:^{
//do something
}];
}
网友评论