编辑内容UIWebView时隐藏键盘

时间:2013-08-06 22:11:18

标签: iphone ios uiwebview virtual-keyboard

我的项目包中的UIWebView显示了一个html文件。我想在UIWebView中编辑输入时隐藏ios键盘并显示我自己的虚拟键盘(用Jquery编写)。在UIWebView中编辑内容时是否可以隐藏键盘?我不能对元素使用blur()方法,因为我想编辑内容。我需要在没有ios键盘的情况下这样做吗?

我找到了解决方案。

- (void)viewDidLoad
{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]]];
    self.webView.delegate=self;

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

    [super viewDidLoad];

}
- (void)esconde {
     for (UIWindow *keyboardWindow in [[UIApplication sharedApplication]
windows])
         for (UIView *keyboard in [keyboardWindow subviews])
             if([[keyboard description] hasPrefix:@"<UIPeripheralHostView"]
== YES)                             [keyboard removeFromSuperview];
}
- (void)keyboardWillShow:(NSNotification *)aNotification {
[self performSelector:@selector(esconde) withObject:nil afterDelay:0];
}

1 个答案:

答案 0 :(得分:1)

我找到了解决方案。

- (void)viewDidLoad
{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]]];
    self.webView.delegate=self;

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

    [super viewDidLoad];

}
- (void)esconde {
     for (UIWindow *keyboardWindow in [[UIApplication sharedApplication]
windows])
         for (UIView *keyboard in [keyboardWindow subviews])
             if([[keyboard description] hasPrefix:@"<UIPeripheralHostView"]
== YES)                             [keyboard removeFromSuperview];
}
- (void)keyboardWillShow:(NSNotification *)aNotification {
[self performSelector:@selector(esconde) withObject:nil afterDelay:0];
}