【问题标题】:Hide keyboard while editing content UIWebView编辑内容时隐藏键盘 UIWebView
【发布时间】:2013-08-06 22:11:17
【问题描述】:

我的项目包中的 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];
}

【问题讨论】:

  • 如果您找到了答案,请将其作为答案发布然后接受,这样其他人就不会在不需要时尝试帮助找到解决方案。它还可以通过表明您找到了解决他们可能遇到的问题的方法来帮助其他人。
  • 我收到一条警告“你不能在两天内接受你的答案”

标签: iphone ios uiwebview virtual-keyboard


【解决方案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];
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-24
    • 1970-01-01
    • 1970-01-01
    • 2019-06-08
    • 2014-03-19
    相关资源
    最近更新 更多