使键盘在ios 4.0上强制消失

时间:2010-09-13 13:17:16

标签: iphone xcode ios4

当TextVIew被激活时,我曾经使用我编写的源码在ios 3.1.3版本上使键盘不可见。(请参阅我的电子邮件的上方或下方。) 但是我不能再用ios 4.0上的源代码使键盘不可见了。 你能告诉我如何在ios 4.0版本上让键盘消失吗?


[[NSNotificationCenter defaultCenter] addObserver:self 
                                      selector:@selector (keyboardWillShow:) 
                                      name:UIKeyboardWillShowNotification 
                                      object:nil];


-(void)keyboardWillShow:(NSNotification *)note 
{
    for(UIWindow *keyboardWindow in [[UIApplication sharedApplication] windows]) 
    {
        for(UIView *keyboard in [keyboardWindow subviews]) 
        {
            if( [[keyboard description] hasPrefix:@"<UIKeyboard"]==YES) 
            {
                [keyboard setBounds:CGRectMake(keyboard.frame.origin.x+1000, 
                                               keyboard.frame.origin.y+1000,
                                               keyboard.frame.size.width, 
                                               keyboard.frame.size.height)];
            }
        }
    }
}

1 个答案:

答案 0 :(得分:1)

为什么不去resignFirstResponder?