Search code examples
iphoneobjective-cioscore-animation

Staggered iOS animation


I would like to perform a simple animation on a series of UIImageViews in my app. I have a grid of images that I want to fade in. I can make it so that the next image starts its animation after the previous one completes, like so:

|--------animation1--------|

                            |--------animation2--------|

                                                        |--------animation3--------|

Which I accomplish with code like this:

- (void)loadOtherIcon;
{
    UIImageView *icon = [icons objectAtIndex:iconCount];
    [UIView animateWithDuration:0.5 delay:0.0 options:nil animations:^{
        icon.alpha = 1;
    } completion:^(BOOL finished){
        if (iconCount < icons.count - 1) {
            [self loadOtherIcon];
        }
    }];
}

But I was hoping to stagger them, like this:

|--------animation1--------|

           |--------animation2--------|

                     |--------animation3--------|

Any suggestions?


Solution

  • Start each of the animations at the same time, but use an increasing "delay" amount. Currently, you're setting it to 0.0.