2012-03-02 51 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轴上弹跳,因此比样本更容易实施。