项目中做了一个底部输入框跟随键盘弹起上移收起返回,只用IQKeyboardManager的时候系统键盘和三方键盘切换的时候底部输入框就自动回收了,而且系统键盘的时候底部输入框弹不起来所以给键盘添加监听以后问题就解决了
//监听当键盘将要出现时
[[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 *)notification
{
//获取键盘的高度
NSDictionary *userInfo = [notification userInfo];
NSValue *value = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
CGRect keyboardRect = [value CGRectValue];
int height = keyboardRect.size.height;
[self.view bringSubviewToFront:self.scrollView];
[UIView animateWithDuration:0.5 animations:^{
CGRect frame = self.bottomView.frame;
frame.origin.y = self.view.height - height - SKWidth(46);
self.bottomView.frame = frame;
}];
}
//当键退出
- (void)keyboardWillHide:(NSNotification *)notification
{
//获取键盘的高度
NSDictionary *userInfo = [notification userInfo];
NSValue *value = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
CGRect keyboardRect = [value CGRectValue];
int height = keyboardRect.size.height;
if (height == 0) {
[self.view sendSubviewToBack:self.scrollView];
}
[self.view bringSubviewToFront:self.scrollView];
[UIView animateWithDuration:0.5 animations:^{
CGRect frame = self.bottomView.frame;
frame.origin.y = self.view.height - self.bottomView.height;
self.bottomView.frame = frame;
}];
}
网友评论