0

Im dynamically creating textFields on UIScrollView, I'm animating View to bring textField above the keyboard if keyboard is hiding it. To animate View is used code given below:

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    CGRect textFiledFrame = textField.frame;

    if (textFiledFrame.origin.y > 219 && textField.tag > 150 && viewAnimated == 0) {
        CGRect superViewFrame = textField.superview.frame;
        superViewFrame.origin.y = superViewFrame.origin.y - 120;
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.6];
        [textField.superview setFrame:superViewFrame];
        [UIView commitAnimations];
        viewAnimated = 1;
    }
}

for every single time i'm clicking on textFields textFieldDidBeginEditing:(UITextField *)textField is being call but once view get animated, textFieldDidBeginEditing:(UITextField *)textField is not being called

wali naqvi
  • 952
  • 1
  • 12
  • 21

1 Answers1

0

There are several things wrong with your code:

  • You should not hardcode any keyboard related sizes. Instead make use of the keyboard information the iOS framework provides you (see e.g. here: How to make a UITextField move up when keyboard is present?)

  • You do set ViewAnimated = 1 in your if statement - do you ever rest it to 0? If not, the if statement will never be entered again, as you check on ViewAnimated == 0 in the if clause ...

  • Variables should not start with a capital letter (Rect, ViewAnimated) - better is textRect en viewAnimated

Community
  • 1
  • 1
TheEye
  • 8,809
  • 2
  • 38
  • 56
  • Yes i make ViewAnimated to 0 after moving it down.and in my application every information about textFields are coming from web,For the same Srollview the number of textFields can be 2 or it can be 200 also.thats why i used this logic.As far as this issue is concern i have resolved it,I'll give answer and i'll accept it. – wali naqvi Mar 25 '14 at 09:55
  • You really should not do it like that - look into the link I provided, and check the answer that uses contentInsets for the scroll view, that's the best way to do it. You don't need to fiddle around with booleans and frames etc. to do it then, that's always prone to errors. – TheEye Mar 25 '14 at 10:19