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

时间:2014-09-21 22:35:24

标签: ios objective-c facebook animation facebook-pop

当用户输入错误的输入时,我使用Facebook POP框架为UILabelsUITextFields制作动画。我想在Mac上输入错误的密码时模拟弹簧动画的类型。

我正在编写这种方法来制作摇动动画:

- (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不做任何事情。它根本不像动画,只是对画面的调整。

1 个答案:

答案 0 :(得分:1)

不是向POPSpringAnimation图层和textField图层添加相同的label,而是制作两个POPSpringAnimation并为每个图层添加一个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]; 。像这样:

{{1}}