我的项目包中的UIWebView显示了一个html文件。我想隐藏ios键盘并在UIWebView中编辑输入时显示自己的虚拟键盘(用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];
}

最佳答案



我找到了解决方案。

- (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];
}

关于iphone - 编辑内容UIWebView时隐藏键盘,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18091427/

10-14 18:36
查看更多