使图像跳转IOS

时间:2012-08-04 21:05:28

标签: objective-c ios xcode image cocoa-touch

我需要将图像设置为15个单位,慢下来(不是立即停止),然后再回来。我对此很新,不知道该怎么做。我希望有人能帮帮忙。如果您需要更多信息,请与我们联系。谢谢!

2 个答案:

答案 0 :(得分:3)

你可以使用2路径:CABasicAnimation或UIView动画(代码差别不大)。 UIView对简单动画更简单,更好。 CAAnimation需要Quartz框架,并且具有更低的偏好。这两个指南有助于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;
 }

答案 1 :(得分: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];