UITextField动画完成,但在用户触摸后弹出回到原始位置 [英] UITextField Animation completes, but then pops back to original spot after user touches

查看:53
本文介绍了UITextField动画完成,但在用户触摸后弹出回到原始位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个 UITextField ,它们通过setFrame:方法进行动画处理.动画本身效果很好,但是当用户在屏幕上进行触摸时,问题是在动画之前开始的.发生的是,所有三个 UITextField 都消失了.

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.

要注意的一件事是,当我按取消",然后按重新实例化动画的按钮时, UITextField 重新出现,并且仍然具有用户先前输入的字符串.因此,这并不是说它们实际上正在消失……我想只是在视觉上消失了.

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.

我得到的代码:

- (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];
}

我试图通过将setFrame:的调用方式从setFrame更改为 [self.fullnameTextField sefFrame:...] 来进行切换.否则,我真的想不起任何哈哈.

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.

有人有什么主意吗?

推荐答案

您是否正在使用自动布局(iOS 6功能,该功能根据称为约束的算术规则控制控件的放置)?要查看是否具有自动布局功能,请打开情节提要/NIB,然后按 option + command - 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.

这篇关于UITextField动画完成,但在用户触摸后弹出回到原始位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆