Iphone 在iOS中隐藏UIButton的动画

Iphone 在iOS中隐藏UIButton的动画,iphone,ios,animation,Iphone,Ios,Animation,在我的应用程序中,我想给ui按钮一个动画,就像按钮在隐藏时会“掉出来”一样 我尝试了以下代码,但没有给我一个好的结果 [UIView animateWithDuration:1.5 animations:^{ S1Button.frame = CGRectMake(20, 10, 50, 10); }]; [S1Button setHidden:YES]; break; 使用具有完成块的动

在我的应用程序中,我想给
ui按钮
一个动画,就像按钮在隐藏时会“掉出来”一样

我尝试了以下代码,但没有给我一个好的结果

[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];
    }]
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;
            }];
试试这个

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:0.9 animations:^{
        tradeButton.frame = (CGRect){ CGPointMake(51, 150), tradeButton.bounds.size };
    } completion:^(BOOL finished) {
        tradeButton.hidden = YES;
        // etc.
    }];

您可以设置新位置并在动画后隐藏按钮。

  [UIView animateWithDuration:0.9 animations:^{
        tradeButton.frame = (CGRect){ CGPointMake(51, 150), tradeButton.bounds.size };
    } completion:^(BOOL finished) {
        tradeButton.hidden = YES;
        // etc.
    }];
试试这个:

如果在动画完成之前隐藏按钮,则无动画可见。因此,用以下代码替换您的代码:

[UIView animateWithDuration:1.5 animations:^{
    S1Button.frame = CGRectMake(20, 10, 50, 10);
} completion:^(BOOL finished) {
    [S1Button setHidden:YES];
}];

break;
试试这个:

如果在动画完成之前隐藏按钮,则无动画可见。因此,用以下代码替换您的代码:

[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];

在代码中,按钮的隐藏属性不可设置动画。当此动画块运行时,按钮将立即隐藏,但不会褪色/设置动画。淡出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];

您想让按钮在下落时被看到吗?您想让按钮在下落时被看到吗?