//第一種直接在textview的狀態里判斷 記得寫textview的委托
- (void)textViewDidBeginEditing:(UITextView *)textView { bKeyBoardHide = NO; } - (void)textViewDidEndEditing:(UITextView *)textView { bKeyBoardHide = YES; }
第二種 鍵盤監控 [[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotificationobject:nil]; [[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotificationobject:nil]; -(void)keyboardWillHide:(NSNotification *)notification { NSLog(@"*-----HideKeyBoard"); bKeyBoardHide = YES; } -(void)keyboardWillShow:(NSNotification *)notification { NSLog(@"*-----ShowKeyBoard"); bKeyBoardHide = NO; } /* @implementation UIView (FindAndResignFirstResponder) - (BOOL)findAndResignFirstResponder { if (self.isFirstResponder) { [self resignFirstResponder]; return YES; } for (UIView* subView in self.subviews) { if ([subView findAndResignFirstResponder]) return YES; } return NO; } @end //自動尋找並釋放第一焦點 - (BOOL) TTIsKeyboardVisible { // Operates on the assumption that the keyboard is visible if and only if there is a first // responder; i.e. a control responding to key events UIWindow* window = [UIApplication sharedApplication].keyWindow; return [window findAndResignFirstResponder]; } */