Ios 动画UIButton';s的头衔变更

Ios 动画UIButton';s的头衔变更,ios,cocoa-touch,uibutton,core-animation,Ios,Cocoa Touch,Uibutton,Core Animation,在这里,我找到了如何使用现在已弃用的beginAnimations:context:方法设置UIButton标题更改的动画: 如何使用当前的API做同样的事情 更新: 我尝试使用基于块的动画: NSTimeInterval animationDuration = animated ? 1.f : 0.f; [UIView animateWithDuration:animationDuration delay:0.f options:UIViewAnimationOptionBeginFromC

在这里,我找到了如何使用现在已弃用的
beginAnimations:context:
方法设置
UIButton
标题更改的动画:

如何使用当前的API做同样的事情

更新:

我尝试使用基于块的动画:

NSTimeInterval animationDuration = animated ? 1.f : 0.f;
[UIView animateWithDuration:animationDuration delay:0.f options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionAllowUserInteraction animations:^{
    [button setTitle:newTitle forState:UIControlStateNormal];
    [button setTitleColor:newTitleColor forState:UIControlStateNormal];
} completion:nil];
颜色更改未设置动画。

使用块:

[UIView transitionWithView:self.flipLabelButton duration:1 options:UIViewAnimationOptionTransitionFlipFromRight animations:^{

    [self.flipLabelButton setTitle:newText forState:UIControlStateNormal];

} completion:nil];

除AnimationGroup外,通常有两种动画,一种用于属性动画,另一种用于为内容、过渡或无法使用属性进行动画的任何内容设置动画。 因此,第二种解决方案是您的选择,您可以通过两种方式实现: 使用CATTransition:

CATransition *transition = [CATransition animation];
transition.type = kCATransitionFade;
transition.duration = 1;
[button.layer addAnimation:transition forKey:kCATransition];
[button setTitle:newTitle forState:UIControlStateNormal];
[button setTitleColor:newColor forState:UIControlStateNormal];
另一种方法是使用UIKit块,正如@jv360所说, 但是你不能在里面设置颜色的动画,因为很明显颜色不能翻转。

Swift

UIView.transition(with: button, duration: 0.5, options: .transitionCrossDissolve, animations: {
  self.button.setTitle("WOW, new title", for: .normal)
  self.button.setTitleColor(UIColor.red, for: .normal)
}, completion: nil)

请检查文档,在UIView参考:中对tt进行了解释,并清楚地解释了
beginAnimations:context:
replacement。就这样?我认为只有记录为“可设置动画”的属性才能以这种方式设置动画。或者没有?如果你使用的是动画函数,但是过渡函数适用于所有的东西,因为它适用于整个视图。我已经更新了我的问题。它仍然没有动画。有什么想法吗?你用的是动画而不是转场。。。它应该是
[UIView transitionWithView:按钮持续时间:动画持续时间选项:UIViewAnimationOptionTransitionFlipFromRight animations:^{
…如果您想要淡入淡出效果,您也可以使用
UIViewAnimationOptionTransitionCrossDissole