Showing and hiding keyboard on second UITextField edit

I have many UItextField, and an animation liked to them:

-(void)textFieldDidBeginEditing: (UITextField *)textField{
NSLog(@"sowing keyboard");

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.27];
scroll1.frame = CGRectMake(0, -604, 768, 1004);
[UIView commitAnimations];

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.47];
scroll2.frame = CGRectMake(0, 414, 768, 1004);
[UIView commitAnimations];



[UIView animateWithDuration:1.0
                 animations:^{ 
                     self.mapView.alpha=0.0;
                 } 
                 completion:^(BOOL finished){
                     self.mapView.hidden=YES;
                 }];


}

 -(void)textFieldDidEndEditing: (UITextField *)textField{
NSLog(@"hiding keyboard");

if (scroll2.frame.origin.y != 414) {

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.27];
scroll1.frame = CGRectMake(0, -340, 768, 1004);
[UIView commitAnimations];

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.47];
scroll2.frame = CGRectMake(0, 678, 768, 1004);
[UIView commitAnimations];

[self.mapView setHidden:NO];

//fade in
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];

[self.mapView setAlpha:1.0];

[UIView commitAnimations];

    }
}

The problem is that if I am editing a field, and from their i touch and start to edit another field, the code didEnd and then DidBegin are called. How can I stop that?? I would like these animations only to occur when i start editing a text field and no text fields are being edited, and the DidEnd when I need to hide the keyboard (when the user presses the DownKey on iPad)

Any ideas??

I tried this:

if (scroll2.frame.origin.y != 414) {

...it works but when I press the rerun key, no animation occurs.

Answers


The textField in question sends itself along with the argument to textFieldDidBeginEditing.

Add an if () block to test for textField1 and textField2 ie:

-(void)textFieldDidBeginEditing:(UITextField *)textField {
if (textField == textField1) {
    //do animation linked to textField1
}
if (textField == textField2) {
    //do animation linked to textField2
}
}

Also, you should implement this method

-(BOOL)textFieldShouldReturn:(UITextField *)textField {
    //handles the enter/done key
    //perform whatever action for when user touches return
    if (textField == textField1) {
        [textField2 becomeFirstResponder];
    } else {
        [textField1 becomeFirstResponder];
    }
    return YES or NO;
}

Need Your Help

Manipulate a Password

java security password-protection

My Java application manipulates a password that is eventually used to encrypt a file.

Parallel Repa code doesn't create sparks

haskell parallel-processing monads repa data-parallel-haskell

I'm writing code to do a subset product: it takes a list of elements and a list of indicator variables (of the same length). The product is computed in a tree, which is crucial to our application. ...