項(xiàng)目中做了一個(gè)底部輸入框跟隨鍵盤彈起上移收起返回级解,只用IQKeyboardManager的時(shí)候系統(tǒng)鍵盤和三方鍵盤切換的時(shí)候底部輸入框就自動回收了冒黑,而且系統(tǒng)鍵盤的時(shí)候底部輸入框彈不起來所以給鍵盤添加監(jiān)聽以后問題就解決了
//監(jiān)聽當(dāng)鍵盤將要出現(xiàn)時(shí)
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
//監(jiān)聽當(dāng)鍵將要退出時(shí)
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
//當(dāng)鍵盤出現(xiàn)
- (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;
}];
}
//當(dāng)鍵退出
- (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;
}];
}