是否可以在MKAnnotationView而不是MKPinAnnotationView中调用animatesDrop?

Mat*_*Mat 9 iphone view mkannotation

你知道吗MKPinAnnotationView有一个方法"animatesDrop"来动画一个引脚注释从顶部到地图上的阴影点?好的,是否可以使用自定义图像执行此操作?

gca*_*amp 21

您始终可以在MKMapViewDelegate方法中执行自定义动画.

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
Run Code Online (Sandbox Code Playgroud)

可能是这样的(你不会得到花哨的阴影动画,如果你想要它你需要自己做):

- (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];
    }
}
Run Code Online (Sandbox Code Playgroud)

Swift版本

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()
    }
}
Run Code Online (Sandbox Code Playgroud)