// 键盘即将显示
[[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 *)note
{
// 取出动画时间
CGFloat duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue];
// 取出键盘高度
CGRect keyboardFrame = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGFloat keyboardHeight = keyboardFrame.size.height;
[UIView animateWithDuration:duration delay:0 options:7 << 16 animations:^{
//底部工具条弹出的高度就是键盘弹出的高度
self.toolbar.transform = CGAffineTransformMakeTranslation(0, -keyboardHeight);
} completion:nil];
}
- (void)keyboardWillHide:(NSNotification *)note
{
CGFloat duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue];
[UIView animateWithDuration:duration delay:0 options:7 << 16 animations:^{
self.toolbar.transform = CGAffineTransformIdentity;
} completion:nil];
}