Search code examples
iosobjective-cgravity

Is There Anyway I can make my image jump then fall back down


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];

Solution

  • 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);
            }];
        }
    }];