2011-07-17 7 views
5

Mam widok mapy. Zaimplementowałem didAddAnnotationViews, aby pokazać niestandardowe zanikanie animacji dla moich pinezek.odpowiednik "didAddAnnotationViews" do usuwania pinów?

Jest to wywoływane z powodzeniem po dodaniu szpilek do mapy, ale nie po usunięciu szpilek. Nie mogę znaleźć równoważnej funkcji w dokumentacji. Czy istnieje inny sposób zaimplementowania niestandardowej animacji zaniku dla określonych pinów?

+0

Chciałbym żeby to wiedzieć! –

Odpowiedz

3

nie ma metody Delegat usuwanie adnotacji, ale można osiągnąć efekt animowane następujący sposób:

Kiedy chcesz usunąć adnotację, zanikać swój pogląd na zewnątrz z animacją i usunąć adnotację, gdy animacja uzupełnia. You kod może wyglądać następująco:

[UIView animateWithDuration:0.5f animations:^(void){ 
          annotationView.alpha = 0.0f; 
         } 
       completion:^(BOOL finished){ 
        [mapView removeAnnotation:annotation]; 
       }]; 
+1

Jak uzyskać widok adnotacji? – Shmidt

+2

@Dima z viewForAnnotation: metoda w MKMapView – Vladimir

5

Utworzyłem kategorię do MKMapView z następujących metod

- (void)removeAnnotation:(id<MKAnnotation>)annotation animated:(BOOL)shouldAnimate; 
- (void)removeAnnotations:(NSArray *)annotations animated:(BOOL)shouldAnimate; 

że można zadzwonić zamiast dzwonić

- (void)removeAnnotation:(id<MKAnnotation>)annotation; 
- (void)removeAnnotations:(NSArray *)annotations; 

Oto realizacja:

- (void)removeAnnotation:(id<MKAnnotation>)annotation animated:(BOOL)shouldAnimate { 
    if (!shouldAnimate) 
     [self removeAnnotation:annotation]; 
    else { 
     MKAnnotationView *annotationView = [self viewForAnnotation:annotation]; 
     CGRect endFrame = annotationView.frame; 
    endFrame = CGRectMake(
         annotationView.frame.origin.x, 
         annotationView.frame.origin.y - self.bounds.size.height, 
         annotationView.frame.size.width, 
         annotationView.frame.size.height); 
    [UIView animateWithDuration:0.3 
          delay:0.0f 
         options:UIViewAnimationOptionAllowUserInteraction 
        animations:^{ 
         annotationView.frame = endFrame; 
        } 
        completion:^(BOOL finished) { 
         [self removeAnnotation:annotation]; 
        }]; 
    } 
} 

- (void)removeAnnotations:(NSArray *)annotations animated:(BOOL)shouldAnimate { 
    if (!shouldAnimate) 
     [self removeAnnotations:annotations]; 
    else { 
     NSTimeInterval delay = 0.0; 
     for (id<MKAnnotation> annotation in annotations) { 
      MKAnnotationView *annotationView = [self viewForAnnotation:annotation]; 
      CGRect endFrame = annotationView.frame; 
      endFrame = CGRectMake(
           annotationView.frame.origin.x, 
           annotationView.frame.origin.y - self.bounds.size.height, 
           annotationView.frame.size.width, 
           annotationView.frame.size.height); 
      [UIView animateWithDuration:0.3 
            delay:delay 
           options:UIViewAnimationOptionAllowUserInteraction 
          animations:^{ 
           annotationView.frame = endFrame; 
          } 
          completion:^(BOOL finished) { 
           [self removeAnnotation:annotation]; 
          }]; 
      delay += 0.05; 
     } 
    } 
}