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:
- when keyboard appears, webview shifted up
- when keyboard dismisses, webview not shifted down
what did far applying following techniques read others:
1) observe keyboard notification, , adjust after that
2) change meta tag, add "height=device-height" in 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
Post a Comment