2011-07-17 8 views
5

Tengo una vista de mapa. Implementé didAddAnnotationViews para mostrar un fundido personalizado en la animación de mis pines.equivalente a "didAddAnnotationViews" para eliminar los pines?

Esto se llama con éxito cuando se agregan los pines al mapa, pero no cuando se quitan los pines. No puedo encontrar una función equivalente en la documentación. ¿Hay alguna otra manera de implementar una animación personalizada de fundido de salida para pasadores específicos?

+0

Me gustaría para saber esto también! –

Respuesta

3

No hay métodos de delegado para la eliminación de anotaciones, pero se puede conseguir un efecto de animación de la siguiente manera:

Cuando se desea eliminar la anotación, primero desvanecerse su punto de vista con la animación y eliminar la anotación cuando la animación completa. Usted código puede verse como:

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

¿Cómo se obtiene una anotación? – Shmidt

+2

@Dima con viewForAnnotation: método en MKMapView – Vladimir

5

He creado la categoría a la MKMapView con los siguientes métodos

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

que puede llamar en lugar de llamar

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

Aquí está la aplicación:

- (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; 
     } 
    } 
} 
Cuestiones relacionadas