代码之家  ›  专栏  ›  技术社区  ›  WoodenKitty

iphonemapkit:别针一个一个掉下来

  •  3
  • WoodenKitty  · 技术社区  · 14 年前

    我正在使用mkmapview并在上面添加图钉。我想一个接一个地掉下去,而不是同时掉下去。原来我是打电话来的

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

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

    1 回复  |  直到 11 年前
        1
  •  3
  •   Gordon Hughes    14 年前

    - (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
                                }
                             }];
    }