今天在寫鍵盤彈出和退出時候,利用通知監(jiān)聽事件
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
偶然發(fā)現(xiàn)在使用搜狗第三方鍵盤時候忿偷,有些卡頓金顿。
打斷點發(fā)現(xiàn):
鍵盤彈出的時候,UIKeyboardWillShowNotification鲤桥,這個通知監(jiān)聽的方法居然進了3次揍拆,而且監(jiān)聽到的鍵盤高度居然不一致。
最終的解決方法:
#pragma mark - 鍵盤通知的方法
-(void)keyboardWillShow:(NSNotification *)notification{
NSDictionary *keyBordInfo = [notification userInfo];
DDLog(@"keyBordInfo = %@",keyBordInfo);
NSValue *value = [keyBordInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
CGRect keyBoardRect = [value CGRectValue];
float height = keyBoardRect.size.height;
CGRect beginRect = [[keyBordInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
CGRect endRect = [[keyBordInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
DDLog(@"keyBordInfo.height = %f",height);
// 第三方鍵盤回調(diào)三次問題芜壁,監(jiān)聽僅執(zhí)行最后一次
if(beginRect.size.height > 0 && (beginRect.origin.y - endRect.origin.y > 0)){
//do someing
}
}