繁体   English   中英

UIButton动画问题-iOS

[英]UIButton Animation issue - iOS

我正在尝试处理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];

                 }];

在继续操作之前,您需要确保将finish设置为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];
                     }
                 }];

问题是您在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是大多数动画的默认设置。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM