Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iphone consecutive animations

I'm wondering what the best way is to implement a series of different animations. If I call the following method and try to animate the same object right, left, and up, for instance, it won't work, because the compiler doesn't deal with them in a linear fashion, and I end up with my object simply going up (skipping the steps to go right and left):

    -(IBAction)clickStart
{
    [self Animation1];
    [self Animation2];
    [self Animation3];

}

Now I could to this, but it somehow feels cumbersome and weird to me. Consider this is the method for Animation1:

[pageShadowView setFrame:CGRectMake(100, 0, CGRectGetWidth(pageShadowView.frame), CGRectGetHeight(pageShadowView.frame))];

        [UIView beginAnimations:@"Animation1" context:nil]; // Begin animation
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(Animation2)];

    [pageShadowView setFrame:CGRectMake(200, 0, CGRectGetWidth(pageShadowView.frame), CGRectGetHeight(pageShadowView.frame))];

    [UIView commitAnimations]; // End animations

And then I could do the same in Animation2, i.e. to call Animation3 once it is done. But to be honest, this is very confusing and not a very clear coding method. Is there anyway to get a more 'linear' code like the one I've suggested at the beginning (which doesn't work), or will I simply have to live with the selector-method?

Thanks for any suggestions!

like image 849
n.evermind Avatar asked Nov 27 '25 09:11

n.evermind


1 Answers

If you don't have to support iOS < 4:

[UIView animateWithDuration:0.2 animations:^{
    // animation 1
} completion:^(BOOL finished){
    [UIView animateWithDuration:0.2 animations:^{
        // animation 2
    } completion^(BOOL finished){
        [UIView animateWithDuration:0.2 animations:^{
            // animation 3
        }];
    }];
}]
like image 144
mxcl Avatar answered Nov 30 '25 00:11

mxcl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!