当用户在 UIWebView 中点击时,默认键盘如何出现? [英] How the default keyboard comes up when user taps in UIWebView?

查看:12
本文介绍了当用户在 UIWebView 中点击时,默认键盘如何出现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发像 Mogok 这样的自定义 iOS 浏览器.当用户点击 UIWebView 中的任何文本输入时,我需要更改默认键盘.

I am currently developing a custom iOS browser something like Mogok. I need to change the default keyboard when user taps on any textinput in the UIWebView.

我想知道当用户点击 UIWebView 中的任何输入文本时系统如何显示键盘?如何获取在 UIWebView 中成为第一响应者的文本字段的引用?

I wonder how the system shows keyboard when a user taps on any input text in UIWebView? How can I get the reference of the text field which becomes first responder in UIWebView?

推荐答案

好吧,如果你不能打败他们,加入他们.

Well, if you can't beat them, join them.

据我所知,我试过了.如果不使用私有类 (UIWebBrowserView),则无法更改 inputView 或 inputAccessoryView.

As far as I know, and I tried. You can't change the inputView or the inputAccessoryView without using a private class (UIWebBrowserView).

但是您可以检测键盘何时出现,通知 UIKeyboardWillShowNotification.那么,做个中间人怎么样?我的意思是,像缓冲区一样使用 UITextField.

But you can detect when the keyboard appears, with the notification UIKeyboardWillShowNotification. So, how about do a man in the middle? I mean, use a UITextField like a buffer.

让我再解释一下.

当键盘出现时,你可以检查第一响应者是否是UIWebView,如果是,你可以成为一个textview作为第一响应者.

When the keyboard appears, you can check if the first responder is the UIWebView, if it is, you can become a textview as the first responder.

你有什么收获?用键盘输入的文本转到文本视图.你会说,那是没用的.当然,但是改变textview的输入视图怎么样?如何?有了这个 https://github.com/kulpreetchilana/Custom-iOS-Keyboards

What do you win with that? The text typed with the keyboard go to the text view. That is useless, you would say. Of course, but how about change the input view of the textview? How? With this https://github.com/kulpreetchilana/Custom-iOS-Keyboards

当用户在 Web 视图中书写时,您有一个自定义键盘!!!

You have a custom keyboard when the user is writing in the web view!!!

如何将 textview 的文本放入 webview 中?很简单,用textViewDidChange和javascript将textview的文本放到内部html的输入中.

How can you put the textview's text in the webview? Easy, Put the textview's text in the input of the inner html with textViewDidChange and javascript.

- (void)textViewDidChange:(UITextView *)textView{
    NSString* script = [NSString stringWithFormat:@"document.activeElement.value = '%@';", textView.text];   
    [self stringByEvaluatingJavaScriptFromString:script];
}

我把这个想法的主要短语加粗.但是,也许我的解释很难理解.或者我的英语不好,所以我上传了一个示例 项目 .

I put in bold the main phrases of the idea. But, maybe my explanation is difficult to understand. Or my English is bad, so I uploade a sample project with the idea.

这篇关于当用户在 UIWebView 中点击时,默认键盘如何出现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆