2012-08-04 54 views
0

我需要图像来像15个单位的屏幕一样,放慢速度(不是立即停止),然后再回落。我对此很新,不知道该怎么做。我希望有人能帮帮忙。如果您需要更多信息,请与我们联系。谢谢!制作一个图像跳转IOS

回答

1

您将带有图像的UIImageView和带有向上动画的animateWithDuration:delay:options:animations:completion:。在动画块中,您只需更改图像视图的frame

options你使用UIViewAnimationOptionCurveEaseOut上涨。

一旦完成,您立即使用UIViewAnimationOptionCurveEaseIn立即开始第二个动画。因此,

NSTimeInterval durationUp = 1.5; 
[UIView animateWithDuration:durationUp delay:0.0 
    options:UIViewAnimationOptionCurveEaseOut 
    animations:^{ 
     CGRect f = imageView.frame; 
     f.origin.y += 15; 
     imageView.frame = f; 
    } 
    completion:nil]; 

[UIView animateWithDuration:1.5 delay:durationUp 
    options:UIViewAnimationOptionCurveEaseIn 
    animations:^{ 
     CGRect f = imageView.frame; 
     f.origin.y -= 15; 
     imageView.frame = f; 
    } 
    completion:nil]; 
+0

图像上升速度非常快,下来很慢。我怎样才能让它跳得更快,但速度更快下降。我很想批准你是否可以提供帮助。 – user1438042 2012-08-04 21:42:55

+0

尝试摆弄持续时间。 – Mundi 2012-08-04 23:22:32

+0

我有一些原因,我不能让动画的拳头部分工作。它总是传送起来 – user1438042 2012-08-04 23:48:18

3

您可以使用2路径:CABasicAnimation或UIView动画(代码差异不是很大)。 UIView对于简单的动画更简单和更好。 Quartz框架中的CAAnimation需求,也有更低的偏好。这两个指南将帮助http://www.raywenderlich.com/2454/how-to-use-uiview-animation-tutorialhttp://www.raywenderlich.com/5478/uiview-animation-tutorial-practical-recipes

使用CAAnimation简单(为例):

-(void)animationRotation 
{ 
     CABasicAnimation *anim; 
     anim = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; 
     anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]; // this what you need - slow down (not an immediate stop) 
    anim.duration = 0.5; 
    anim.repeatCount = 1; 

     anim.fromValue = [NSNumber numberWithFloat:0]; 
     [anim setDelegate:self];  

     anim.toValue = [NSNumber numberWithFloat:(15)]; 
     [myView.layer addAnimation:anim forKey:@"transform"]; 

     CGAffineTransform rot = CGAffineTransformMakeTranslation(15.0); 
     myView.transform = rot; 
} 
相关问题