Search code examples
iphonecore-animation

using series of animations on different images one after another


I need to do series of animation on 4 different images. The images are arranged in sequence. It will begin with movement of first image and when it stops the second one will move and similarly others will follow. Can someone please help me?

Thanks in advance

Pankaj

Answer

[UIView animateWithDuration:2.0
                 animations:^{ 
                     ballon1.center = CGPointMake(260, 50);
                 } 
                 completion:^(BOOL finished){

                     [UIView animateWithDuration:1.5
                                      animations:^{ 
                                          ballon2.center = CGPointMake(260, 140);
                                      } 
                                      completion:^(BOOL finished){
                                              [UIView animateWithDuration:1.0
                                                               animations:^{ 
                                                                   ballon3.center = CGPointMake(260, 230);
                                                               } 
                                                               completion:^(BOOL finished){
                                                                   [UIView animateWithDuration:1.0
                                                                                    animations:^{ 
                                                                                        ballon4.center = CGPointMake(260, 320);
                                                                                    } 
                                                                                    completion:^(BOOL finished){
                                                                                        ;
                                                                                    }];
                                                               }];

                                          }
                                      ];

                 }];

Solution

  • You can do something like this:

    [UIView animateWithDuration:1 animations:^{
        self.image1.frame = [self frameForImage1];
    } completion:^(BOOL finished){
        [UIView animateWithDuration:1 animations:^{
            self.image2.frame = [self frameForImage2];
        } completion:^(BOOL finished){
           // etc. for images 3 and 4
        }];
    }];
    

    Or if you'd rather do your animations using beginAnimations:context: and commitAnimation, then you can use setAnimationDelegate: and setAnimationDidStopSelector: to chain together a series of selectors to animate each image.