views:

26

answers:

3

I need to move the view up when the keyboard is shown but only for 1 textfield at the bottom of my view, I thought it would be as easy as checking for isFirstResponder but no such luck - here is what I was trying:

if ([notes isFirstResponder]) {

    [UIView beginAnimations:@"moveupcontrols" context:nil];
    [UIView setAnimationDuration:.25];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    self.view.frame=CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y-kOrderFormKeyboardHeight, self.view.frame.size.width,  self.view.frame.size.height)  ;
    [UIView commitAnimations];

    keyboardIsShown = YES;
}

I am assuming the notification fires before the FirstResponder flag is set on my textfield. Thoughts on a work around for this?

+2  A: 

Why not use the UITextField -textFieldShouldBeginEditing: delegate method? This will get called before editing begins, and you can perform your animations there.

Ben Gottlieb
worked great, thanks
Slee
A: 

Why dont you set a tag to that text field and add the same code to textFieldDidBeginEditing delegate method? You will have to check for the tag value instead of isFirstResponder.

lukya
A: 

Here is some code for you to do:

- (void)viewDidLoad {
  textField1.tag = 1;
  textField2.tag = 2;

  textField1.delegate = self;
  textField2.delegate = self;
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
  if (textField.tag == 1) {
    // then animation here
  }
}

Don't forget to comform to UITextFieldDelegate protocol.

More about tag here. More about UITextFieldDelegate here

vodkhang