我有一个初始文本“开始”连接到Interface中的动作的开始按钮。
然而,动画立即开始和结束,而不是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更新:当然,这些响应是正确的。我采用了杰克·吴的建议,尽管没有隐藏文本,但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];
}}];
}发布于 2014-01-15 21:57:54
按钮的标题不是一个可动的属性,所以您将看到它立即返回。那是故意的。您可以在UIView的“文档”中找到它的可动画属性。今天的情况如下。
@property frame
@property bounds
@property center
@property transform
@property alpha
@property backgroundColor
@property contentStretch或者,您可以在按钮中添加两个子视图标签,并在动画中交叉淡出它们。
发布于 2014-01-15 21:59:54
标题不是UIButton的可动画属性。正如其他人所建议的那样,您需要自己创建一个动画,方法是删除按钮,更改标题,然后将其淡出。
您还可以编写自定义动画代码,获取按钮的位图快照,将其放在当前按钮的顶部,更改位图快照下的按钮标题,然后淡出并删除位图。这会给你一个交叉褪色的影响,但这将是一个相当大的工作量。
https://stackoverflow.com/questions/21148643
复制相似问题