4

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?

halfer
  • 19,824
  • 17
  • 99
  • 186
TechBee
  • 1,897
  • 4
  • 22
  • 46
  • Are you wanting to show a custom keyboard (inputView, or inputAccessoryView) or do you just want a different system keyboard like @BlackRider is suggesting? – TomSwift Nov 13 '13 at 20:13
  • Yes thru inputView or inputAccessoryView @Tom – TechBee Nov 14 '13 at 10:53

2 Answers2

9

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.

dcorbatta
  • 1,893
  • 19
  • 15
  • Is the code from a subclass or category of `UIWebView`? Because if not why are you calling self? It would be `[self.webViewInstance stringByEva...` or `[webViewInstance stringByEva...` Please can you provide more code to explain your code. – Popeye Nov 19 '13 at 16:17
  • I'm sorry, I paste a portion of code where the textview is a private property of my webview subclass. Let me upload the entire project to github. – dcorbatta Nov 19 '13 at 18:14
-1

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

TotoroTotoro
  • 17,524
  • 4
  • 45
  • 76