简体   繁体   English

UITextField动画完成,但在用户触摸后弹出回到原始位置

[英]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. 我有三个UITextField ,它们通过setFrame:方法进行动画处理。 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. 发生的是三个UITextField消失了。

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. 需要注意的一件事是,当我按下“取消”,然后按下重新实例化动画的按钮时, UITextField再次出现,并且仍然具有用户先前输入的字符串。 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: ...] . 我尝试通过将setFrame:从setFrame更改为[self.fullnameTextField sefFrame: ...]来切换setFrame:的调用方式。 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)? 您是否正在使用自动布局(iOS 6功能,该功能根据称为约束的算术规则控制控件的放置)? 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. 要查看是否具有自动布局,请打开情节提要/ NIB,然后按Option + Command - 1转到“文件检查器”(或仅单击最右侧面板上的“文件检查器”选项卡),然后查看是否具有“自动布局”是否检查。

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. 有关如何通过更改约束进行动画制作的示例,请参见此答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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