2012-03-02 49 views
0

任何人都可以指導我在正確的方向上搞清楚如何動畫像這樣一個UIImageView:的UIImageView「跳出」

在應用程序的初始加載,一個UIImageView將的頂部進入屏幕上,然後在底部沉降幾次後(上下)反彈到底部。

我知道如何使它沿着Y軸移動,但如何在最後做輕微的反彈效果?

謝謝!

回答

0

實現這一目標的一種方法(我使用這種方法取得了巨大成功)是使用嵌套動畫。你可以利用UIView + (void)animateWithDuration:animations方法。

這裏的它:

Animation{ 
    //Fall to the bottom along the y axis 
    [self doFallToBottom]; 
    onCompletion: 
    { 
      Animation{ 
      //Hits the bottom. Bounce up a bit along the y axis (maybe 100 pixels or so) 
      [self bounceUp:100]; 
      onCompletion: 
      { 
       //Fall back down to the bottom along the y axis 
       [self doFallToBottom]; 
      } 
      }  
    } 
} 
+0

雖然這會工作,我會更喜歡,創造出一個CAKeyframeAnimation並添加到它的路徑。添加單個路徑對於我來說比通過動畫結束委託方法跟蹤順序動畫更容易。 – taskinoor 2012-03-02 15:17:26

+0

你的想法聽起來不錯。我最初的擔心是無法管理每個幀的持續時間,但它看起來像CAKeyframeAnimation爲您提供了這種能力。好主意! – Jeremy 2012-03-02 15:19:02

+0

如果我們想要不同的上下速度,那麼我想你的方法會更好。不確定是否可以爲不同的路徑組件設置不同的時間。但是,如果我們想要整體減速,那麼可以使用kCAMediaTimingFunctionEaseOut作爲計時功能。 – taskinoor 2012-03-02 15:26:09

1

MoveMe來自Apple的示例代碼演示了一個彈跳動畫。請在MoveMeView類中檢查方法- (void)animatePlacardViewToCenter。它創建了一個bounceAnimation。由於您只需要在y軸上彈跳,因此比樣本更容易實施。