最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Programmatically display keyboard in UIWebView - Stack Overflow

programmeradmin1浏览0评论

If an element in a UIWebView has the style property -webkit-user-modify:read-write, then pressing on the element causes the keyboard to appear. Is it possible to bring up the keyboard programatically?

Thanks

If an element in a UIWebView has the style property -webkit-user-modify:read-write, then pressing on the element causes the keyboard to appear. Is it possible to bring up the keyboard programatically?

Thanks

Share Improve this question asked Mar 19, 2012 at 23:33 gary_zgary_z 651 silver badge9 bronze badges 1
  • Maybe apply that style to the body? – Chaosphere2112 Commented Mar 20, 2012 at 0:02
Add a ment  | 

2 Answers 2

Reset to default 6

It looks like in iOS6 now you can do this with "keyboardDisplayRequiresUserAction":

keyboardDisplayRequiresUserAction A Boolean value indicating whether web content can programmatically display the keyboard.

@property (nonatomic) BOOL keyboardDisplayRequiresUserAction Discussion When this property is set to YES, the user must explicitly tap the elements in the web view to display the keyboard (or other relevant input view) for that element. When set to NO, a focus event on an element causes the input view to be displayed and associated with that element automatically.

The default value for this property is YES.

Availability Available in iOS 6.0 and later. Declared In UIWebView.h

reference:

From iOS Developer Library:

Because the keyboard is displayed automatically when a view bees the first responder, you often do not need to do anything to display it. However, you can programmatically display the keyboard for an editable text view by calling that view’s beeFirstResponder method. Calling this method makes the target view the first responder and begins the editing process just as if the user had tapped on the view.

I doubt that calling [webView beeFirstResponder] will bring up the keyboard as long as no HTML element with the required style has the focus. So your real problem might be to set the focus in your HTML document to an element programmatically. I would try to do this via Javascript. Something like this might work:

NSString *jscode = @"document.getElementById('whatever').focus();";
[self.webView stringByEvaluatingJavaScriptFromString:jscode];
发布评论

评论列表(0)

  1. 暂无评论