1

I have three UITextFields that I have animating in by a setFrame: method. The animation itself works great, but the problem begins prior to the animation when the user makes touches on the screen. What occurs is that all three UITextFields disappear.

One thing to note is that when I press cancel, and then press the button that re-instantiates the animation, the UITextFields reappear and also still have the string that was previously entered by the user. So it's not like they're actually disappearing... Just visually disappearing I suppose.

The code I've got:

- (IBAction)signupPressed:(UIButton *)sender
{
    self.isSigningUp = YES;
    [UIView animateWithDuration:0.3f
                          delay:0.0f
                        options:UIViewAnimationOptionCurveEaseOut
                     animations:^{
                         self.krtiqueButton.alpha = 0.0f;
                         self.krtiqueButton.enabled = NO;
                         self.facebookButton.alpha = 0.0f;
                         self.facebookButton.enabled = NO;
                     } completion:^(BOOL finished){
                         if (finished) {
                             [self animateSignUpCredentials];
                         }
                     }];
}
- (void)animateSignUpCredentials
{
    [UIView animateWithDuration:0.3f
                          delay:0.0f
                        options:UIViewAnimationOptionCurveEaseOut
                     animations:^{
                         self.fullnameTextField.frame = CGRectMake(20, 59, 280, 30);
                         self.emailTextField.frame = CGRectMake(20, 97, 280, 30);
                         self.passwordTextField.frame = CGRectMake(20, 135, 280, 30);
                         self.continueButton.alpha = 1.0f;
                     } completion:nil];
}

I've tried switching up the way that setFrame: is called by changing it from setFrame, to [self.fullnameTextField sefFrame: ...]. Otherwise, I can't really think of anything haha.

Anybody got any ideas?

jakenberg
  • 2,125
  • 20
  • 38

1 Answers1

1

Are you using autolayout (an iOS 6 feature that controls the placement of controls based upon arithmetic rules called constraints)? To see if you have autolayout on, open your storyboard/NIB, press option+command-1 to go to the "file inspector" (or just click on the "file inspector" tab on the rightmost panel) and see if "autolayout" is checked or not.

If autolayout is on, even after changing frames, the constraints will be reapplied, and the control will be moved back to the location dictated by the constraints. You can either turn off autolayout, or leave autolayout on and either programmatically remove the constraints or programmatically change the constraints rather than changing the frame.

See this answer for an example of how you might animate by changing constraints.

Community
  • 1
  • 1
Rob
  • 415,655
  • 72
  • 787
  • 1,044
  • i got a warning when disabling autolayout. Will this give me any problems when i do the auto layout on my app? – rohaldb Feb 22 '16 at 05:59
  • In 2013, when I wrote this answer, disabling auto layout was an acceptable approach, but nowadays I'd suggest (a) always keeping autolayout turned on; (b) changing `constant` of `IBOutlet` of constraint; and (c) animate call to `layoutIfNeeded`. See http://stackoverflow.com/questions/14189362/animating-an-image-view-to-slide-upwards/14190042#14190042 – Rob Feb 22 '16 at 10:11