views:

126

answers:

1

Hi. I'm using an mkmapview and dropping pins on to it. I would like the pins to fall one by one, rather than all simultaneously. Originally I was calling

[self performSelector:@selector(dropPin) withObject:nil afterDelay:dropTime];

where dropTime was a different delay for each pin, and dropPin was a method to make the pin drop. Unfortunately the multithreading behind this seems to cause a crash.

Does anyone know a better way?

Thanks!

A: 

If you're targeting iOS4, blocks are a great way to handle animations without worrying about delegates, callbacks, or selectors:

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
    if ([views count] == 0) {
        return;
    }
    MKAnnotationView *aV;
    for (aV in views) {
        // set up pin beginning and end frames, shadow subview frame and center

        [UIView animateWithDuration:0.75
                              delay:(0.0 + [views indexOfObject:aV]/10.0)
                            options:UIViewAnimationOptionCurveEaseOut
                         animations:^{
                             [aV setFrame:endFrame];
                             // animate the shadow subview's center point
                         }
                         completion:^ (BOOL finished) {
                            if (finished) {
                                // do something here when the animation finished
                            }
                         }];
}
Gordon Hughes
It would be great to have an iOS 3 compatible solution.
Sam V