3

我正在使用 mkmapview 并在其上放置图钉。我希望引脚一个接一个地掉下来,而不是同时掉下来。本来我在打电话

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

其中 dropTime 是每个引脚的不同延迟,而 dropPin 是一种使引脚掉落的方法。不幸的是,这背后的多线程似乎会导致崩溃。

有谁知道更好的方法?

4

1 回答 1

3

如果您的目标是 iOS4,块是处理动画的好方法,而无需担心委托、回调或选择器:

- (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
                            }
                         }];
}
于 2010-08-31T02:51:38.040 回答