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

ε祈祈猫儿з 提交于 2020-01-05 12:58:12

问题


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?


回答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.



来源:https://stackoverflow.com/questions/14432574/uitextfield-animation-completes-but-then-pops-back-to-original-spot-after-user

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!