Is it possible to call animatesDrop in MKAnnotationView and not in MKPinAnnotationView?

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

+8
iphone view mkannotation
Jan 26
source share
3 answers

You can always make your own animations in the MKMapViewDelegate method.

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

Probably something like this (you won’t get an attractive shadow animation, if you want, 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]; } } 
+20
Jan 26 '10 at 12:35
source share

Same answer as @gcamp , only in Swift for interested

 func mapView(mapView: MKMapView, didAddAnnotationViews views: [MKAnnotationView]) { let visibleRect = mapView.annotationVisibleRect for view:MKAnnotationView in views{ let endFrame:CGRect = view.frame var startFrame:CGRect = endFrame startFrame.origin.y = visibleRect.origin.y - startFrame.size.height view.frame = startFrame; UIView.beginAnimations("drop", context: nil) UIView.setAnimationDuration(1) view.frame = endFrame; UIView.commitAnimations() } } 
+3
Aug 08 '15 at 10:34
source share

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

 - (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]; } } 
+1
Jan 01 '13 at
source share



All Articles