我有一個開始按鈕,其初始文本「開始」與界面生成器中的操作相關聯。使用animationWithDuration更改UIButton的標題沒有任何延遲或動畫
但是,動畫會立即開始並結束,而不是持續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];
}}];
}
你確定按鈕的標題是動畫嗎? – Caleb
我不確定你在這裏期待什麼...... – Jack
如果你想要某種過渡,也許你可以在1.5秒內淡出按鈕,改變文字,然後再將它淡入1.5秒? – Jack