ios - UIWebView automatically is shifted up after keyboard appears -


my uiwebview shifted when keyboard appears, , when keyboard dismisses, webview not come previous position. i've checked out webview's position before , after keyboard appears, or dismisses. surprise, webview's frame not changed. i've seen before , after quite different.

  • before keyboard appears:

before

  • when keyboard appears, webview shifted up

appears

  • when keyboard dismisses, webview not shifted down

after

what did far applying following techniques read others:

1) observe keyboard notification, , adjust after that

observe keyboard notification

2) change meta tag, add "height=device-height" in meta tag

meta tag

3) change webview's attributes:

 _webview.contentmode = uiviewcontentmodescaleaspectfit; _webview.scalespagetofit = yes; _webview.autoresizingmask = (uiviewautoresizingflexibleheight | uiviewautoresizingflexiblewidth); 

however, of these suggestion above not work. please me?

note: use ios7, xcode 5

a uiwebview has uiscrollview in manage content bigger screen. when adjust height of uiscrollview has impact on it's scroll position. when shrink height keyboard causes content scroll keep text field visible (by modifying contentoffset), when expand height shows more content @ bottom , doesn't change contentoffset original value.

there slews of ways come @ problem , creates editable text deals @ point. i've used many on years i'm sure there better ones haven't seen.

the way did last modifying contentinset of uiscrollview , saving off original contentoffset can re-populate later.

set notifications

[[nsnotificationcenter defaultcenter] addobserver:self                                          selector:@selector(keyboardwillshow:)                                              name:uikeyboardwillshownotification object:nil];  [[nsnotificationcenter defaultcenter] addobserver:self                                          selector:@selector(keyboardwillhide:)                                              name:uikeyboardwillhidenotification object:nil]; 

do stuff on notifications

- (void)keyboardwillshow:(nsnotification *)notification {     nsdictionary *userinfo = [notification userinfo];     cgrect keyboardrect = [[userinfo objectforkey:uikeyboardframebeginuserinfokey] cgrectvalue];     cgfloat keyboardheight = uiinterfaceorientationisportrait(self.interfaceorientation)?keyboardrect.size.height:keyboardrect.size.width;     cgfloat duration = [[userinfo objectforkey:uikeyboardanimationdurationuserinfokey] floatvalue];     cgfloat animationstyle = [[userinfo objectforkey:uikeyboardanimationcurveuserinfokey] floatvalue];      self.tableviewoffset = self.tableview.contentoffset     uiedgeinsets contentinsets = self.tableview.contentinset;     contentinsets.bottom = keyboardheight;      [uiview animatewithduration:duration delay:0 options:animationstyle animations:^{         self.tableview.contentinset = contentinsets;     } completion:nil]; }  - (void)keyboardwillhide:(nsnotification *)notification {     nsdictionary *userinfo = [notification userinfo];     cgfloat duration = [[userinfo objectforkey:uikeyboardanimationdurationuserinfokey] floatvalue];    cgfloat animationstyle = [[userinfo objectforkey:uikeyboardanimationcurveuserinfokey] floatvalue];      uiedgeinsets contentinsets = self.tableview.contentinset;     contentinsets.bottom = 0;      [uiview animatewithduration:duration delay:0 options:animationstyle animations:^{         self.tableview.contentinset = contentinsets;         self.tableview.contentoffset = self.tableviewoffset;     } completion:nil]; } 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -