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

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.

Leave a Comment