Alba Ocram
Alba Ocram

Reputation: 27

Chaining UIView animations?

I am trying to make an image start at coordinates x=80 and y=249 which would move to x=284 and y=99. Then from there it would go to x=488 and y=249.

This is what i got, but for some reason the image starts at x=284 and y=99 and moves to x=488 and y=249. I need help to fix this issue.

    -(void)BallArchR{
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration: 1.5];
        [UIView setAnimationCurve:UIViewAnimationCurveLinear];
        CGPoint center = [Ball center];
        center.x = 284;
        center.y = 99;
        [Ball setCenter:center];
        [UIView commitAnimations];
        [self BallArchR2];
    }

    -(void)BallArchR2{
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration: 1.5];
        [UIView setAnimationCurve:UIViewAnimationCurveLinear];
        CGPoint center = [Ball center];
        center.x = 488;
        center.y = 249;
        [Ball setCenter:center];
        [UIView commitAnimations];
    }

Upvotes: 0

Views: 132

Answers (1)

DharaParekh
DharaParekh

Reputation: 1730

because of you call BallArchR2 method from BallArchR method directly. But in actual, the animation of BallArchR method is not complete and before that BallArchR2 method is called. So, call BallArchR2 method after the completion of first BallArchR method animation. So you can Try this hope it helps you:

-(void)BallArchR{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration: 1.5];
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    CGPoint center = [Ball center];
    center.x = 284;
    center.y = 99;
    [Ball setCenter:center];
    [UIView commitAnimations];

    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 1.55 * NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        [self BallArchR2];
    });
}

-(void)BallArchR2{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration: 1.5];
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    CGPoint center = [Ball center];
    center.x = 488;
    center.y = 249;
    [Ball setCenter:center];
    [UIView commitAnimations];
}

Upvotes: 2

Related Questions