keyboard in UIWebView shows and then hides itself on input focus
I have a page that's loading into a UIWebView (which takes 100% of the screen) on an iPad.
When I touch a text field, the page positions the text field to the right place and the keyboard starts to come up, but then it turns around and goes back down and blur is called on the input field.
When I try this same page in mobile Safari, the keyboard is able to deploy successfully.
I can't figure o开发者_如何学Cut what the rules are for the keyboard to show successfully and stay up = and why this is different for uiwebview than safari.
All my research on the subject has yielded no answers.
Without having any code posted in your question, I am speculating that the keyboard going back down occurs only when the HTML text field is touched prior to the final call to UIWebViewDelegate webViewDidFinishLoad:
To test this, first set your UIWebView.delegate
to the UIViewController
that owns it (or whatever object owns the UIWebView
). Then implement these delegate methods.
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSString *urlString = request.URL.absoluteString;
NSLog(@"%@ with URL = %@", NSStringFromSelector(_cmd), urlString);
return YES;
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
NSString *urlString = webView.request.URL.absoluteString;
NSLog(@"%@ with URL = %@", NSStringFromSelector(_cmd), urlString);
}
Run your app and make note of the number of times that webViewDidFinishLoad:
is called. (If your web page contains multiple frames or includes things like Google Analytics, it will be called multiple times.)
Try touching the HTML text field after `webViewDidFinishLoad:' is called for the final time. Does the keyboard stay up? (I would think so).
If that works, next try to get a touch in before the final call to `webViewDidFinishLoad:'. Does the keyboard animate up but then back down?
精彩评论