0

我正在尝试处理 UIButton 动画,其中按钮移动到一个点,然后将隐藏设置为 true。但是,当我尝试处理以下代码时,按钮甚至在动画完成之前就消失了。我做得对吗?有什么建议么?

[UIView animateWithDuration:0.8
                 animations:^{

                     selectedCurveIndex = 0;
                     [tradebutton moveTo:
                      CGPointMake(51,150) duration:0.8 
                                  option:curveValues[UIViewAnimationOptionCurveEaseInOut]];
                 }
                 completion:^(BOOL finished){ 

                     [tradeButton setHidden:TRUE];

                     UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
                     UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"ButtonView"];

                     self.modalPresentationStyle = UIModalPresentationCurrentContext;
                     [self presentModalViewController:vc animated:NO];

                 }];
4

2 回答 2

1

在继续之前,您需要确保已完成设置为YES 。

您的按钮隐藏得很快,因为0.8是一个快速动画持续时间。您将需要找出另一个隐藏按钮的位置,或者您可以

试试这个:

[UIView animateWithDuration:0.8
                 animations:^{

                     selectedCurveIndex = 0;
                     [tradebutton moveTo:
                      CGPointMake(51,150) duration:0.8 
                                  option:curveValues[UIViewAnimationOptionCurveEaseInOut]];
                 }
                 completion:^(BOOL finished){ 

                     if ( finished ) 
                     {    
                         [tradeButton performSelector:@selector(setHidden:) withObject:@"YES" afterDelay:3.0];

                         UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
                         UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"ButtonView"];

                         self.modalPresentationStyle = UIModalPresentationCurrentContext;
                         [self presentModalViewController:vc animated:NO];
                     }
                 }];
于 2012-07-25T03:13:19.640 回答
0

问题是您在该moveTo:duration:option:方法中创建了第二个内部动画块,并在该内部块中设置了所有可动画属性。您没有在外部块中设置任何动画属性。

这意味着系统立即认为外部动画已经完成,并立即调用完成块。同时,内部动画块仍在进行中。

停止使用moveTo:duration:option:。它几乎没有为您节省任何费用,并最终给您带来这样的麻烦。把它扔掉并尝试这样的事情:

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

请注意,这UIViewAnimationOptionCurveEaseInEaseOut是大多数动画的默认设置。

于 2012-07-25T03:52:43.927 回答