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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With