Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MapView Custom annotation drop

I am trying to create a custom annotation for the map. The problem I have is , I can't make the annotation drop one after the other. All pins drop down at the same time. Here is the delegate code for didAddAnnotations. Can you help me to rewrite the code so that I can make the custom annotations drop one after the other..just like it happens when we use default annotations. Thanks in advance....!!!!

- (void) mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {

    CGRect visibleRect = [mapView annotationVisibleRect]; 

    for (MKAnnotationView *view in views) {
        CGRect endFrame = view.frame;

        CGRect startFrame = endFrame;
        startFrame.origin.y = visibleRect.origin.y - startFrame.size.height;
        view.frame = startFrame;

        [UIView beginAnimations:@"drop" context:NULL]; 
        [UIView setAnimationDuration:1];

        view.frame = endFrame;

        [UIView commitAnimations];
    } // end of for 
} // end of delegate
like image 245
bp581 Avatar asked Sep 02 '26 07:09

bp581


1 Answers

You could add a delay that becomes a little longer in each iteration of your loop, like this:

double delay = 0.0;
for (MKAnnotationView *view in views) {
    CGRect endFrame = view.frame;
    CGRect startFrame = endFrame;
    startFrame.origin.y = visibleRect.origin.y - startFrame.size.height;
    view.frame = startFrame;
    [UIView beginAnimations:@"drop" context:NULL];
    [UIView setAnimationDuration:1.0];
    [UIView setAnimationDelay:delay];
    view.frame = endFrame;
    [UIView commitAnimations];
    delay += 0.1;
}
like image 183
omz Avatar answered Sep 04 '26 21:09

omz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!