ios - UILabel 和 UITextField 的动画(Facebook POP 框架)

标签 ios objective-c facebook animation facebook-pop

当用户输入错误时,我使用 Facebook POP 框架为 UILabelsUITextFields 设置动画。想在mac上模拟输入错误密码时的那种 Spring 动画。

我写了这个方法来做摇动动画:

- (void)shakeAnimation:(UITextField *)textField :(UILabel *)label
{
  //This method takes a textField and a label as input, and animates them accordingly. 
  //When the animation is done, the button is available for touch again, and the animation is removed.

  POPSpringAnimation *positionAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerPositionX];
  positionAnimation.springBounciness = 20; //just parameters, nothing fancy
  positionAnimation.velocity = @4000;
  [positionAnimation setCompletionBlock:^(POPAnimation *animation, BOOL finished) {
    self.signUpButton.userInteractionEnabled = YES;
  }];
  [textField.layer pop_addAnimation:positionAnimation forKey:@"positionAnimation"];
  [label.layer pop_addAnimation:positionAnimation forKey:@"positionAnimation"];
  [positionAnimation removedOnCompletion];

}

但是,当我这样调用此方法时:[self shakeAnimation:self.emailField :self.emailLabel];

UILabels 只向右移动大约 50px 然后停止移动,而 UITextFields 什么都不做。看起来根本不像是动画,只是调整了帧数。

最佳答案

不要将相同的 POPSpringAnimation 添加到 textField 层和 label 层,而是制作两个 POPSpringAnimation s 并为每个加一。像这样:

POPSpringAnimation *anim1 = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerPositionX];
anim1.springBounciness = 20; //just parameters, nothing fancy
anim1.velocity = @400;
[anim1 setCompletionBlock:^(POPAnimation *animation, BOOL finished) {
    self.button.userInteractionEnabled = YES;
}];

POPSpringAnimation *anim2 = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerPositionX];
anim2.springBounciness = 20; //just parameters, nothing fancy
anim2.velocity = @400;

[textField.layer pop_addAnimation:anim1 forKey:@"positionAnimation"];
[label.layer pop_addAnimation:anim2 forKey:@"positionAnimation"];

[anim1 removedOnCompletion];
[anim2 removedOnCompletion];

关于ios - UILabel 和 UITextField 的动画(Facebook POP 框架),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25964581/

相关文章:

asp.net - AddThis Facebook 发送按钮不显示

Android Facebook 登录问题?

ios - 节点未在 Swift 2 和 SpriteKit 中加载纹理

ios - 将 CoreBluetooth 与 iBeacon 结合使用

objective-c - 替换字符串中的所有字符

ios - NSDateFormatter 格式化日期的星期几

ios - 最新的 Facebook SDK 是否会自动检查其应用程序是否已安装?它说它会......但它不会发生在我身上

ios - PhoneGap访问来源限制无效

ios - map View :didDeselectAnnotationView: delegate method getting called before the annotation view is actually deselected

objective-c - XCode 4 中的 "Validate"