2010-01-26 80 views

回答

20

您可以随时在MKMapViewDelegate方法中执行自定义动画。

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

也许类似的东西(你不会得到花哨的影子动画,如果你想它,你需要自己做):

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

@gcamp:我也尝试以这种方式,但无法正常工作(图像不改变): MKPinAnnotationView * annView = [MapView的dequeueReusableAnnotationViewWithIdentifier:ident]上; annView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:ident] autorelease]; annView.image = [UIImage imageNamed:@“annotImg.png”]; annView.animatesDrop = TRUE; – Mat 2010-01-26 12:45:37

+0

更改了我的答案! – gcamp 2010-01-26 13:04:57

+0

非常感谢!这对我来说非常有用! – Mat 2010-01-26 19:59:58

1

感谢@gcamp的回答,它的工作原理不错,但我稍作修改是准确的,其视图将在MapView的被丢弃,请检查下面的代码:只在斯威夫特

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

相同的答案@gcamp对于那些有兴趣

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() 
    } 
} 
相关问题