Ios 使用animationWithDuration更改UIButton的标题没有延迟或动画

Ios 使用animationWithDuration更改UIButton的标题没有延迟或动画,ios,objective-c,animation,uibutton,Ios,Objective C,Animation,Uibutton,我有一个开始按钮,初始文本“开始”连接到Interface Builder中的操作 但是,动画立即开始和结束,而不是花费3+5秒。这个代码有什么问题 @interface ViewController() @property (weak, nonatomic) IBOutlet UIButton *startButton; @end @implementation ViewController - (IBAction)startPressed:(UIButton *)sender {

我有一个开始按钮,初始文本“开始”连接到Interface Builder中的操作

但是,动画立即开始和结束,而不是花费3+5秒。这个代码有什么问题

@interface ViewController()
@property (weak, nonatomic) IBOutlet UIButton *startButton;
@end

@implementation ViewController

- (IBAction)startPressed:(UIButton *)sender
{
    [UIView animateWithDuration:3 delay:5
        options:UIViewAnimationOptionCurveEaseInOut
        animations:^{
            [self.startButton setTitle:@"New Title" forState:UIControlStateNormal];
        } 
        completion:nil];
}

@end
更新:当然,这些回答是正确的。我使用了Jack Wu的建议,但是在不隐藏文本的情况下,setTitle使按钮在屏幕上闪烁

- (IBAction)startPressed:(UIButton *)sender
{
    [UIView animateWithDuration:1.5 delay:5
        options:UIViewAnimationOptionCurveEaseInOut
                     animations:^{ self.startButton.alpha = 0; }
                     completion:^(BOOL c){ if (c) {
        self.startButton.hidden = YES;
        [self.startButton setTitle:@"newTitle" forState:UIControlStateNormal];
        [UIView animateWithDuration:1.5 delay:0 options:UIViewAnimationOptionCurveEaseInOut
                         animations:^{
                             self.startButton.hidden = NO;
                             self.startButton.alpha = 1;
                         }
                         completion:nil];

    }}];
}

按钮的标题不是可设置动画的属性,因此您将看到它立即返回。那是故意的。您可以在其“”中找到UIView的可设置动画的属性。以下是截至今天的情况

@property frame
@property bounds
@property center
@property transform
@property alpha
@property backgroundColor
@property contentStretch

或者,您可以向按钮添加两个子视图标签,并在动画中交叉淡入淡出它们。

按钮的标题不是可设置动画的属性,因此您将看到它立即返回。那是故意的。您可以在其“”中找到UIView的可设置动画的属性。以下是截至今天的情况

@property frame
@property bounds
@property center
@property transform
@property alpha
@property backgroundColor
@property contentStretch

或者,您可以向按钮添加两个子视图标签,并在动画中交叉淡入淡出它们。

标题不是UIButton的可设置动画的属性。正如其他人所建议的,您需要通过淡出按钮、更改标题以及淡出等操作来创建动画


您还可以编写自定义动画代码,拍摄按钮的位图快照,将其放在当前按钮的顶部,更改位图快照下的按钮标题,然后淡出并删除位图。这将给你一个交叉淡入淡出的效果,但这将是一个相当大的工作量。

标题不是UIButton的一个可设置动画的属性。正如其他人所建议的,您需要通过淡出按钮、更改标题以及淡出等操作来创建动画


您还可以编写自定义动画代码,拍摄按钮的位图快照,将其放在当前按钮的顶部,更改位图快照下的按钮标题,然后淡出并删除位图。这将给你一个交叉淡入淡出效果,但这将是一个相当大的工作量。

你确定按钮的标题是可动画的吗?我不确定你在这里期望什么…如果你想要某种过渡,也许你可以在1.5秒内淡出按钮,更改文本,然后在1.5秒后淡入?你确定按钮的标题是可设置动画的吗?我不确定你在这里期望的是什么…如果你想要某种过渡,也许你可以在1.5秒后淡出按钮,更改文本,然后在1.5秒后淡入?