Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 22nd, 2012  |  syntax: None  |  size: 1.63 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to animate a image up and down smoothly. iphone [closed]
  2. UIImageView *someImage = .....
  3. CALayer *b = someImage.layer;
  4. // Create a keyframe animation to follow a path to the projected point
  5. CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"scale"];
  6. animation.removedOnCompletion = NO;
  7.  
  8. // Create the path for the bounces
  9. CGMutablePathRef thePath = CGPathCreateMutable();
  10.  
  11. // Start the path at my current location
  12. CGPathMoveToPoint(thePath, NULL, someImage.center.x, someImage.center.y);
  13. CGPathAddLineToPoint(thePath, NULL,20, 500.0);
  14.  
  15. animation.path = thePath;
  16.  
  17. animation.speed = 0.011;
  18. animation.repeatCount = 1000000;
  19.  
  20. // Add the animation to the layer
  21. [someImage addAnimation:animation forKey:@"move"];
  22.        
  23. - (void) showProgressView
  24. {
  25. if (progressViewBack.frame.origin.y == 460.0)
  26. {
  27.     [self.view bringSubviewToFront:progressViewBack];
  28.     [progressViewBack setFrame:CGRectMake(6.0, 460, 308.0, 126.0)];
  29.     [progressViewBack setBounds:CGRectMake(0, 0, 308, 126.0)];
  30.  
  31.     [UIView beginAnimations:nil context:NULL];
  32.     [UIView setAnimationDuration:1.0];
  33.     [UIView setAnimationDelegate:self];
  34.     [progressViewBack setFrame:CGRectMake(6.0, 334.0, 308.0, 126.0)];
  35.     [UIView commitAnimations];
  36. }
  37. else if (progressViewBack.frame.origin.y == 334.0)
  38. {  
  39.     [progressViewBack setFrame:CGRectMake(6.0, 334.0, 308.0, 126.0)];      
  40.     [progressViewBack setBounds:CGRectMake(0, 0, 308.0, 126.0)];
  41.  
  42.     [UIView beginAnimations:nil context:NULL];
  43.     [UIView setAnimationDuration:1.0];
  44.     [UIView setAnimationDelegate:self];
  45.     [progressViewBack setFrame:CGRectMake(6.0, 460.0, 308.0, 126.0)];
  46.     [UIView commitAnimations];
  47. }