ios - UITableView slightly goes up when keyboard hides -
i using uitableview (chattable) along uitabbar (chattabbar) , 1 textfield inside imageview. using autolayout. used following code change views when keyboard appears , disappears.
- (void)keyboardwasshown:(nsnotification*)anotification { nsdictionary* info = [anotification userinfo]; // animation info userinfo nstimeinterval animationduration; cgrect keyboardframe; [[info objectforkey:uikeyboardanimationdurationuserinfokey] getvalue:&animationduration]; [[info objectforkey:uikeyboardframebeginuserinfokey] getvalue:&keyboardframe]; // resize frame [uiview animatewithduration:animationduration delay:0.0 options:uiviewanimationoptioncurveeaseout animations:^{ self.keyboardheight.constant = keyboardframe.size.height - tabbar_height ; [self.view layoutifneeded]; } completion:nil]; if ([chatdata count] != value_zero) { [chattable scrolltorowatindexpath:[nsindexpath indexpathforrow:([chatdata count] - value_one) insection:value_zero] atscrollposition:uitableviewscrollpositionbottom animated:no]; } } - (void)keyboardwillhide:(nsnotification*)anotification { nsdictionary* info = [anotification userinfo]; // animation info userinfo nstimeinterval animationduration; cgrect keyboardframe; [[info objectforkey:uikeyboardanimationdurationuserinfokey] getvalue:&animationduration]; [[info objectforkey:uikeyboardframebeginuserinfokey] getvalue:&keyboardframe]; // set view frame [uiview animatewithduration:animationduration delay:2.0 options:uiviewanimationoptioncurveeaseout animations:^{ self.keyboardheight.constant -= keyboardframe.size.height - tabbar_height; [self.view layoutifneeded]; } completion:nil]; }
now when press return tableview goes littel bit (from screen 2 screen 3). keyboardheight bottom space constraint between tabbar , main view.
(screen 2)
(screen3)
i have tried many things can't able find why tableview going while. (problem there no smooth animation.) (note: have put delay 2.0 show happens in following screenshot(screen 3) othewise it's value 0)
your problem you're changing table view frame when keyboard appears, wrong. need change contentinset property of table view, instead of meddling frames.
- (void)keyboardwillshow:(nsnotification *)notification { cgfloat height = [notification.userinfo[uikeyboardframebeginuserinfokey] cgrectvalue].size.height - self.tabbarcontroller.tabbar.frame.size.height; uiedgeinsets edgeinsets = uiedgeinsetsmake(0.0f, 0.0f, height, 0.0f); _tableview.contentinset = edgeinsets; _tableview.scrollindicatorinsets = edgeinsets; } - (void)keyboardwillhide:(nsnotification *)notification { uiedgeinsets edgeinsets = uiedgeinsetszero; _tableview.contentinset = edgeinsets; _tableview.scrollindicatorinsets = edgeinsets; }
Comments
Post a Comment