Es posible llamar a animatesDrop en un MKAnnotationView en lugar de MKPinAnnotationView?

StackOverflow https://stackoverflow.com/questions/2139222

  •  22-09-2019
  •  | 
  •  

Pregunta

¿sabe usted que MKPinAnnotationView tiene un método "animatesDrop" para animar un pin de anotación desde la parte superior hasta el punto en el mapa con una sombra?OK, es posible hacer esto con una imagen personalizada??

¿Fue útil?

Solución

Siempre se puede hacer su animación personalizada en el método MKMapViewDelegate.

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

Probablemente algo así (no obtendrá la animación de fantasía sombra, si quieres que se necesita para hacerlo usted mismo):

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

Swift Versión

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

Otros consejos

Misma respuesta que @gcamp sólo en Swift para aquellos interesados

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

Gracias por su respuesta @gcamp, funciona bien pero modificarlo un poco para ser exacta para que la vista será dado de baja en MAPview, compruebe el siguiente código:

- (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];
 }
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top