2011-11-10 35 views
1

這是我正在努力完成的。難以鏈接兩個UIView動畫

UILabel將出現在屏幕上100%alpha並使用UIView動畫向上移動80pts。只要動畫結束,我希望它繼續高於80pts,同時淡出到alpha 0.我希望這兩個動畫顯示爲一個無縫動畫。

我想也許我可以做一個UIView動畫,然後在完成塊中放置第二個UIView動畫,如下所示。但是,在執行完成塊之前似乎有延遲,這會阻止兩個動畫顯示爲無縫。

任何人都可以告訴我做我想做的最好的方法嗎?

謝謝!

[UIView animateWithDuration:1.2 delay:0 options:UIViewAnimationCurveLinear animations:^{ 
    myLabel.center = endPoint; 

} 
completion:^(BOOL finished) { 
    [UIView animateWithDuration:1.2 delay:0 options:UIViewAnimationCurveLinear animations:^{     
     myLabel.center = endPoint2; 
     myLabel.alpha = 0; 
     } 
     completion:^(BOOL finished) { 
      NSLog(@"animations complete"); 
    }]; 
}]; 

回答

0

這應該有效。我看不出爲什麼沒有。只需一小部分,檢查finished區塊中的動畫完成情況。因爲這將在動畫過程中處理任何錯誤。此外,如果您打算使這個UILabel可點擊,那麼你需要通過設置標誌UIViewAnimationOptionAllowUserInteraction

[UIView animateWithDuration:1.2 delay:0 options:UIViewAnimationCurveLinear | UIViewAnimationOptionAllowUserInteraction animations:^{ 
     myLabel.center = endPoint; 
     myLabel.alpha = 1; 
    } 
    completion:^(BOOL finished) { 
     if(finished){ 
     [UIView animateWithDuration:1.2 delay:0 options:UIViewAnimationCurveLinear | UIViewAnimationOptionAllowUserInteraction animations:^{     
      myLabel.center = endPoint2; 
      myLabel.alpha = 0; 
      } 
      completion:^(BOOL finished) { 
       NSLog(@"animations complete"); 
     }]; 
     } 
    }]; 
+0

它不工作...以及它的作品,但它不是我尋找的無縫效果。它向上移動80個像素......在短時間內停止,然後繼續最後的80個像素並淡出。我試圖讓它變得無縫,看起來不像兩個動畫。 – sayguh

+0

我對代碼做了一個小的編輯..從第一個動畫中刪除myLabel.alpha = 1,因爲它在動畫開始之前已經設置爲1 – sayguh