How the default keyboard comes up when user taps in UIWebView?

无人久伴 提交于 2019-12-17 06:16:10

问题


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.

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 ? I have already made 2 nights black :-) No result yet :-(

Any help would be highly appreciated.

Regards Ranjan


回答1:


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

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

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.

Let me explain a little more.

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.

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

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

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.




回答2:


You can control which keyboard appears for a text field by changing the type attribute in HTML, e.g. <input type='email'/>

Here's the list of possible types: http://www.whatwg.org/specs/web-apps/current-work/#attr-input-type



来源:https://stackoverflow.com/questions/19961369/how-the-default-keyboard-comes-up-when-user-taps-in-uiwebview

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!