简体   繁体   中英

UITextField Animation completes, but then pops back to original spot after user touches

I have three UITextField s 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 UITextField s disappear.

One thing to note is that when I press cancel, and then press the button that re-instantiates the animation, the UITextField s 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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM