判断虚拟键盘是否打开的代码


//第一种直接在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];
}

*/

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM