1.
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomConstraint;
2.
//添加键盘通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(kbWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(kbWillHide:) name:UIKeyboardWillHideNotification object:nil];
3.
#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;
}
经过上述步骤之后,键盘还弹不出来,而且显示键盘的方法没有调用的话,可以试试使用 common +shit +K 快捷键调出键盘或者隐藏。