iphone - 在编辑内容 UIWebView 时隐藏键盘

标签 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];
}

最佳答案

解决方案

我找到了解决方案。

- (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/

相关文章:

iphone - 输入文本时在 UIAlertView 中启用按钮 - 多个警报 View

iOS 标签不会使用字符串值更新文本,但在 Swift 中打印字符串可以正常工作

ios - UIWebView 并保持事件状态?

iphone - 在 UIWebView 中显示来自相机的图像

ios - StatusBar 文本颜色在 iOS 7 中没有改变

iphone - 托管对象上下文保存和refreshObject :mergeChanges:有什么区别

Iphone AddressBook Framework - 人物属性

ios - NSRange,在段落中找到一个词得到错误的结果

iphone - 当 UIWebView 中弹出 OK-Cancel 警报时,如何自动单击取消?

ios - withUnsafePointers 不可用