1.监听键盘设置Fram
1.1接受键盘通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardFramChange:) name:UIKeyboardWillChangeFrameNotification object:nil];
1.2 改变工具条Fram
- (void)keyboardFramChange:(NSNotification *)notifaction
{
NSLog(@"-----%@",notifaction.userInfo[@"UIKeyboardFrameEndUserInfoKey"]);
CGRect y = [notifaction.userInfo[@"UIKeyboardFrameEndUserInfoKey"] CGRectValue];
_toolBar.y = y.origin.y - _toolBar.height;
}
2.改变工具条约束
2.1接受键盘通知
//添加键盘通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(kbWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(kbWillHide:) name:UIKeyboardWillHideNotification object:nil];
2.2 改变工具条约束
#pragma mark 键盘将显示
-(void)kbWillShow:(NSNotification *)noti{
//显示的时候改变bottomContraint
// 获取键盘高度
NSLog(@"%@",noti.userInfo);
CGFloat kbHeight = [noti.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height;
self.bottomConstraint.constant = kbHeight;
}
#pragma mark 键盘将隐藏
-(void)kbWillHide:(NSNotification *)noti{
self.bottomConstraint.constant = 0;
}