在我的應用程序中,我想給一個動畫UIButtons
,就像按鈕在屏幕上「隱藏」時一樣。在iOS中隱藏UIButton的動畫
我試過下面的代碼,但它沒有給我一個好的結果。
[UIView animateWithDuration:1.5
animations:^{
S1Button.frame = CGRectMake(20, 10, 50, 10);
}];
[S1Button setHidden:YES];
break;
在我的應用程序中,我想給一個動畫UIButtons
,就像按鈕在屏幕上「隱藏」時一樣。在iOS中隱藏UIButton的動畫
我試過下面的代碼,但它沒有給我一個好的結果。
[UIView animateWithDuration:1.5
animations:^{
S1Button.frame = CGRectMake(20, 10, 50, 10);
}];
[S1Button setHidden:YES];
break;
使用具有完成塊的動畫方法並在其中隱藏按鈕。目前,您的隱藏方法會立即運行,因此您看不到動畫。
[UIView animateWithDuration:1 animations:^{
S1Button.frame = CGRectMake(20, 10, 50, 10);
} completion:^(BOOL finished) {
[S1Button setHidden:YES];
}]
[UIView animateWithDuration:0.25f
animations:^{
S1Button.frame = CGRectMake(20, 10, 50, 10);
}completion:^(BOOL completed){
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.3];
S1Button.alpha = 1;
[UIView commitAnimations];
}];
試試這個
To fade out:
[UIView animateWithDuration:0.3 animations:^{
button.alpha = 0;
} completion: ^(BOOL finished) {
button.hidden = YES;
}];
To fade in:
button.alpha = 0;
button.hidden = NO;
[UIView animateWithDuration:0.3 animations:^{
button.alpha = 1;
}];
試試這個:
您在動畫完成之前隱藏按鈕,沒有動畫是可見的。所以,用這種替換代碼:
[UIView animateWithDuration:1.5 animations:^{
S1Button.frame = CGRectMake(20, 10, 50, 10);
} completion:^(BOOL finished) {
[S1Button setHidden:YES];
}];
break;
在你的代碼,按鈕的隱藏屬性不是動畫。當此動畫塊運行時,您的按鈕將立即隱藏,但不會淡入淡出/動畫。淡出UIView的適當方法是將其alpha屬性從1.0移動到0.0,如下所示:
[UIView animateWithDuration:2.0
delay:0.0
options: UIViewAnimationCurveEaseOut
animations:^{S1Button.frame = CGRectMake(20, 10, 50, 10);S1buttonA.alpha = 0;}
completion:nil];
您是否希望在下降時看到按鈕? – AtWork