2010-01-26 5 views

Odpowiedz

20

Zawsze można wykonać niestandardową animację w metodzie MKMapViewDelegate.

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

Prawdopodobnie coś takiego (nie dostanie fantazyjne animacji cień, jeśli chcesz to trzeba to zrobić samemu):

- (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: Mam spróbować także w ten sposób, ale nie działa (obraz nie zmienia się): MKPinAnnotationView * annView = [MapView dequeueReusableAnnotationViewWithIdentifier: ident]; annView = [[[MKPinAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: ident] autorelease]; annView.image = [UIImage imageNamed: @ "annotImg.png"]; annView.animatesDrop = TRUE; – Mat

+0

Zmieniono moją odpowiedź! – gcamp

+0

dziękuję bardzo! .. jest to bardzo przydatne dla mnie! – Mat

1

Dzięki @gcamp za odpowiedź, to działa porządku, ale zmodyfikować go trochę za dokładne dla gdzie widok zostanie zrzucona na MapView, sprawdź poniższy kod:

- (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

samą odpowiedź jak @gcamp tylko w Swift dla zainteresowanych

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() 
    } 
} 
Powiązane problemy