[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
- (void)keyboardWillShow:(NSNotification *)notification
{
NSDictionary *userInfo = [notification userInfo];
NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
CGRect keyboardRect = [aValue CGRectValue];
keyboardRect = [self.view convertRect:keyboardRect fromView:nil];
CGFloat keyboardTop = keyboardRect.origin.y;
CGRect newTextViewFrame = self.view.bounds;
newTextViewFrame.size.height = keyboardTop - self.view.bounds.origin.y;
NSNumber *animationDuration = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
NSTimeInterval duration = [animationDuration doubleValue];
[UIView animateWithDuration:duration animations:^{
}];
}
- (void)keyboardWillHide:(NSNotification *)notification
{
NSDictionary* userInfo = [notification userInfo];
NSNumber *animationDuration = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
NSTimeInterval duration = [animationDuration doubleValue];
[UIView animateWithDuration:duration animations:^{
}];
}
网友评论