-3

I want my image to jump up 7 y-axis Lines or something, but then i want him to fall back down. Any Help?

Heres My Code:

CGRect frame = Guy.frame;
frame.origin.x = frame.origin.x - 0;
frame.origin.y = frame.origin.y - 7;

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.60];
Guy.frame = frame;
[UIView commitAnimations];
rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • 2
    You should look into UIDynamicAnimator and associated classes to do this. If you don't know anything about that, then I would look at the videos from the WWDC 2013 ("Getting Started with UIKit Dynamics"). – rdelmar Apr 13 '14 at 16:49
  • A good one from @rdelmar... Adding to his comment, I would like to point out a tutorial on the same.. http://www.teehanlax.com/blog/introduction-to-uikit-dynamics/ – GenieWanted Apr 13 '14 at 16:56

3 Answers3

1

Try this:

CGRect frame = Guy.frame;
[UIView animateWithDuration:0.6 delay: 0 options:UIViewAnimationCurveEaseInOut  animations: ^{
    Guy.frame = CGRectMake(frame.origin.x, frame.origin.y - 7,
                           frame.size.width, frame.size.height);
} completion: ^(BOOL finished) {
    if (finished) {
        [UIView animateWithDuration:0.6 delay: 0 options:UIViewAnimationCurveEaseInOut  animations: ^{
            Guy.frame = CGRectMake(frame.origin.x, frame.origin.y + 7,
                                   frame.size.width, frame.size.height);
        }];
    }
}];
Josue Espinosa
  • 5,009
  • 16
  • 47
  • 81
  • 2
    Since your down voter didn't have the decency to explain why, I will. Your code doesn't answer the question. The question asks how to animate the image up and then back down again. – rmaddy Apr 13 '14 at 16:52
  • 1
    That looks better though you may wish to specify the animation curve in each direction to give it a better look. – rmaddy Apr 13 '14 at 17:08
0
[UIView animateWithDuration:1.0
    delay: 0.0
    animations:^{
         image.frame = CGRectMake(image.frame.origin.x, image.frame.origin.y-7, image.frame.size.width, image.frame.size.height);
    }
    completion:^(BOOL finished){
        // move it ba
        [UIView animateWithDuration:1.0
             delay: 1.0
             options:UIViewAnimationOptionCurveEaseOut
             animations:^{
                image.frame = CGRectMake(image.frame.origin.x, image.frame.origin.y+7, image.frame.size.width, image.frame.size.height);
             }
             completion:nil];
    }];
phantomhive
  • 145
  • 1
  • 1
  • 11
0
[UIView animateWithDuration:.5 delay:0.0
                    options:UIViewAnimationOptionCurveEaseIn
                 animations:^{
                     CGRect f = imageview.frame;
                     f.origin.y -= 40;
                     imageview.frame = f;
                 }
                 completion:nil];
if (imageview.frame.origin.y) {

 [UIView animateWithDuration:.6 delay:0.1
                                         options:UIViewAnimationOptionCurveEaseIn
                                      animations:^{
                                          CGRect f = imageview.frame;
                                          f.origin.y += 80;
                                          imageview.frame = f;
                                      }
                  completion:nil];}
Rahul K Rajan
  • 776
  • 10
  • 19