javascript - preventing keyboard drops while loading in iOS -
in ios app, need focus on text field, based on user's previous interactions. focusing using javascript well, follows (in viewdidfinshload
method)
if (![focuselement isequaltostring:@""]) { // make keyboard freely appear without user intervention [webview setkeyboarddisplayrequiresuseraction:no]; // first lose previous focus , focus on // clicked element nsstring *jstofocus = [nsstring stringwithformat: @"document.activeelement.blur();document.getelementbyid(\'%s\').focus();", [focuselement utf8string]]; // javascript focuses on input [webview stringbyevaluatingjavascriptfromstring:jstofocus];
this works well. problem when page loads further frames/javascripts, key board drops down , reappears couple of times every new load. guess happening due earlier
[webview setkeyboarddisplayrequiresuseraction:no];
is there (better) way , more importantly, keep keyboard displayed once focused on input element, until user dismisses it.
thanks in advance. nikhil
as work-around problem, introduced property web view, called it
@property bool iskeyboardshown;
by default set no , long keyboad not shown allow loading further frames/elements. however, once focus on desired element set yes , forcibly stop further loading. in short viewshouldstartload...
method looks like
- (bool)webview:(uiwebview *)webview shouldstartloadwithrequest: (nsurlrequest *)request navigationtype: (uiwebviewnavigationtype)navigationtype { if (self.iskeyboardshown) return no; ... further code ...
then introduced keyboard notifications
// set keyboard notifications [[nsnotificationcenter defaultcenter] addobserver: self selector: @selector(keyboardwillbehidden:) name: uikeyboardwillhidenotification object: nil];
and method
- (void) keyboardwillbehidden : (nsnotification *) keyboardhidenotice { self.iskeyboardshown = no; }
so, overall idea focus on element -> show keyboard -> stop further loading long keyboard -> reset loading permissions on keyboard dismissal
this works fine, have further problem:
if user finishes inputing text , presses search
or go
key on keyboard, because keyboard still , iskeyboardshown
property yes
, webview not proceed search unless user taps on lens (dismissing keyboard).
is there way detect search key-press event? note, input not uisearchbar
: (
Comments
Post a Comment