簡體   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