由于第三方键盘是先等系统键盘加载了然后覆盖的,所以高度会有二次变化,实际过程中会有三次变化,我真机用的是搜狗输入法,变化时,高度变化为0->216->253;现解决办法如下
{
CGFloat _currentKeyboardH;
CGFloat _transformY;
}
-(void)viewWillAppear:(BOOL)animated{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
}
#pragma mark --键盘的显示隐藏--
-(void)keyboardWillShow:(NSNotification *)notification{
//键盘最后的frame
CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGFloat height = keyboardFrame.size.height;
//需要移动的距离
if (height > 0) {
_transformY = height-_currentKeyboardH;
_currentKeyboardH = height;
//移动
[UIView animateWithDuration:0.3 animations:^{
self.inPutView.y-=_transformY;
}];
}
}
-(void)keyboardWillHide:(NSNotification *)notification{
[UIView animateWithDuration:0.3 animations:^{
self.inPutView.y+=_currentKeyboardH;
_currentKeyboardH = 0;
}];
}