【发布时间】:2014-02-04 14:01:27
【问题描述】:
我有一个带有初始文本“开始”的开始按钮连接到 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];
}}];
}
【问题讨论】:
-
你确定按钮的标题是动画的吗?
-
我不确定你在这里期待什么......
-
如果你想要某种过渡,也许你可以在 1.5 秒内淡出按钮,更改文本,然后再用 1.5 秒淡入?
标签: ios objective-c animation uibutton