ios - 2 problems with dealing with UITextField behind Keyboard -


i have uitextfield in uitableviewcell in view. there possibility uitextfield can behind keyboard deal using following 2 methods. 1 when keyboard clicked , other when dismissed:

- (void)keyboardnotification:(nsnotification*)notification {     cgsize keyboardsize = [[[notification userinfo] objectforkey:uikeyboardframebeginuserinfokey] cgrectvalue].size;     customcell *cell = (customcell*)[[temptextfield superview] superview];     cgrect textfieldrect = [cell convertrect:temptextfield.frame toview:self.view];     if (textfieldrect.origin.y + textfieldrect.size.height >= [uiscreen mainscreen].bounds.size.height - keyboardsize.height) {         thetableview.contentinset =  uiedgeinsetsmake(0, 0, keyboardsize.height, 0);         nsindexpath *pathofthecell = [thetableview indexpathforcell:cell];         [thetableview scrolltorowatindexpath:[nsindexpath indexpathforrow:pathofthecell.row insection:0] atscrollposition:uitableviewscrollpositiontop animated:yes];     }  }  - (void)keyboardhidenotification:(nsnotification*)notification {     thetableview.contentinset =  uiedgeinsetsmake(0, 0, 0, 0); } 

now works there 2 issues.

  1. the tableview scrolls above keyboard if entire uitextfield below top of keyboard. if keyboard halfway uitextfield being selected, tableview not scroll above keyboard. quick glance looks should work may missing something.

2 . when keyboard below keyboard , tableview scrolls up, in nice animated fashion when click done pops old position. can see why happening how make nice animation revert old position tableview in?

any input appreciated!

update: managed find issue #1. silly mistake. should have added height of textfield origin since measurement going downward. onto #2...

this code fixed both 1 , 2:

- (void)keyboardnotification:(nsnotification*)notification {     cgsize keyboardsize = [[[notification userinfo] objectforkey:uikeyboardframebeginuserinfokey] cgrectvalue].size;     customcell *cell = (customcell*)[[temptextfield superview] superview];     cgrect textfieldrect = [temptextfield convertrect:temptextfield.frame toview:self.view];     if (textfieldrect.origin.y + textfieldrect.size.height >= [uiscreen mainscreen].bounds.size.height - keyboardsize.height) {         nsdictionary *info = [notification userinfo];         nsnumber *number = [info objectforkey:uikeyboardanimationdurationuserinfokey];         double duration = [number doublevalue];         [uiview animatewithduration:duration animations:^{             thetableview.contentinset =  uiedgeinsetsmake(0, 0, keyboardsize.height, 0);         }];         nsindexpath *pathofthecell = [thetableview indexpathforcell:cell];         [thetableview scrolltorowatindexpath:[nsindexpath indexpathforrow:pathofthecell.row insection:0] atscrollposition:uitableviewscrollpositionmiddle animated:yes];     }  }  - (void)keyboardhidenotification:(nsnotification*)notification {     nsdictionary *info = [notification userinfo];     nsnumber *number = [info objectforkey:uikeyboardanimationdurationuserinfokey];     double duration = [number doublevalue];     [uiview animatewithduration:duration animations:^{         thetableview.contentinset =  uiedgeinsetsmake(0, 0, 0, 0);     }]; } 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -