//注册通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
//响应通知
#pragma mark keyboard notification
- (void)keyboardWillShow:(NSNotification *) notification {
float animationDuration = [[[notification userInfo] valueForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
CGFloat height = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height;
CGRect bottomBarFrame = self.mToolBar.frame;
{
[UIView beginAnimations:@"bottomBarUp" context:nil];
[UIView setAnimationDuration: animationDuration];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
bottomBarFrame.origin.y = self.view.bounds.size.height - 44 - height;
self.mToolBar.frame = bottomBarFrame;
[UIView commitAnimations];
}
}
- (void)keyboardWillHide:(NSNotification *) notification {
float animationDuration = [[[notification userInfo] valueForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
CGFloat height = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height;
CGRect bottomBarFrame = self.mToolBar.frame;
if (bottomBarFrame.origin.y < 300)
{
[UIView beginAnimations:@"bottomBarDown" context:nil];
[UIView setAnimationDuration: animationDuration];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
bottomBarFrame.origin.y += height;
self.mToolBar.frame = bottomBarFrame;
[UIView commitAnimations];
}
}