do you know that MKPinAnnotationView has a method "animatesDrop" to animate a pin annotation from the top to point on the map with a shadow? OK, is it possible do this with a custom image??

share|improve this question

2 Answers

up vote 6 down vote accepted

You can always do your custom animation in MKMapViewDelegate method.

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

Probably something like that (you won't get the fancy shadow animation, if you want it you need to do it yourself) :

- (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];
    }
}
share|improve this answer
@gcamp: i've try also in this way but not work (the image not change): MKPinAnnotationView *annView=[mapView dequeueReusableAnnotationViewWithIdentifier:ident]; annView=[[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:ident]autorelease]; annView.image =[UIImage imageNamed:@"annotImg.png"]; annView.animatesDrop=TRUE; – Mat Jan 26 '10 at 12:45
Changed my answer! – gcamp Jan 26 '10 at 13:04
thanks much!..this is very useful for me! – Mat Jan 26 '10 at 19:59
1  
Nice work! Found this link as well, which is very similar … so now all we need is the squish effect at the end. Probably another animation that momentarily squishes the image height at the tail end. stackoverflow.com/questions/1857160/… – Joe D'Andrea Jun 13 '10 at 22:15

Thanks @gcamp for your answer, it works fine but I modify it a bit to be accurate for where the view will be dropped on mapView, check the below code:

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
CGRect visibleRect = [mapView annotationVisibleRect];
for (MKAnnotationView *view in views)
 {
    CGRect endFrame = view.frame;
    endFrame.origin.y -= 15.0f;
    endFrame.origin.x += 8.0f;
    CGRect startFrame = endFrame;
    startFrame.origin.y = visibleRect.origin.y - startFrame.size.height;
    view.frame = startFrame;

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

    view.frame = endFrame;

    [UIView commitAnimations];
 }
}
share|improve this answer

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.