首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用UIButton更改animationWithDuration标题没有延迟或动画

问使用UIButton更改animationWithDuration标题没有延迟或动画
EN

Stack Overflow用户
提问于 2014-01-15 21:30:57
回答 2查看 2.5K关注 0票数 1

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

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

代码语言:javascript
复制
@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

更新:当然,这些响应是正确的。我采用了杰克·吴的建议,尽管没有隐藏文本,但setTitle使按钮在屏幕上闪烁。

代码语言:javascript
复制
- (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];

    }}];
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-01-15 21:57:54

按钮的标题不是一个可动的属性,所以您将看到它立即返回。那是故意的。您可以在UIView的“文档”中找到它的可动画属性。今天的情况如下。

代码语言:javascript
复制
@property frame
@property bounds
@property center
@property transform
@property alpha
@property backgroundColor
@property contentStretch

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

票数 4
EN

Stack Overflow用户

发布于 2014-01-15 21:59:54

标题不是UIButton的可动画属性。正如其他人所建议的那样,您需要自己创建一个动画,方法是删除按钮,更改标题,然后将其淡出。

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21148643

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档