iOS8之後蘋果能夠安裝第三方鍵盤,ide
經過斷點咱們會發現使用第三方鍵盤以後,spa
鍵盤將要彈出的方法:- (void)keyBoardWillShow:(NSNotification *)notification會執行三次,code
三次的高度分別是:0:216:282。咱們發現咱們須要的是第三次的高度。server
咱們須要註冊鍵盤隱藏和顯示的通知:blog
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyBoardDidHide:) name:UIKeyboardWillHideNotification object:nil];事件
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];animation
1 #pragma mark–鍵盤顯示事件 2 3 - (void)keyboardWillShow:(NSNotification *)notification { 4 CGFloat curkeyBoardHeight = [[[notification userInfo] objectForKey:@"UIKeyboardBoundsUserInfoKey"] CGRectValue].size.height; 5 CGRect begin = [[[notification userInfo] objectForKey:@"UIKeyboardFrameBeginUserInfoKey"] CGRectValue]; 6 CGRect end = [[[notification userInfo] objectForKey:@"UIKeyboardFrameEndUserInfoKey"] CGRectValue]; 7 8 // 第三方鍵盤迴調三次問題,監聽僅執行最後一次 9 if(begin.size.height>0 && (begin.origin.y-end.origin.y>0)){ 10 11 CGFloat keyBoardHeight = curkeyBoardHeight; 12 13 NSLog(@"第三次:%f",keyBoardHeight); 14 [UIView animateWithDuration:0.05 animations:^{ 15 self.bgView.hidden = NO; 16 self.commentToolView.y = kScreenHeight - keyBoardHeight - 44; 17 18 }]; 19 } 20 } 21 22 #pragma mark–鍵盤隱藏事件 23 24 -(void)keyBoardDidHide:(NSNotification *)notification{ 25 NSLog(@"鍵盤隱藏"); 26 self.bgView.hidden = YES; 27 self.commentToolView.y = kScreenHeight; 28 }