¿Cómo puedo saber cuándo MKMapView setRegion: animada: ha terminado?

votos
18

Quiero establecer una región en mi MKMapView y luego encontrar las coordenadas correspondientes a la esquina NE y SW del mapa.

This code works just fine to do that:
//Recenter and zoom map in on search location
MKCoordinateRegion region =  {{0.0f, 0.0f}, {0.0f, 0.0f}};
region.center = mySearchLocation.searchLocation.coordinate;
region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[self.mapView setRegion:region animated:NO]; //When this is set to YES it seems to break the coordinate calculation because the map is in motion

//After the new search location has been added to the map, and the map zoomed, we need to update the search bounds
//First we need to calculate the corners of the map so we get the points
CGPoint nePoint = CGPointMake(self.mapView.bounds.origin.x + mapView.bounds.size.width, mapView.bounds.origin.y);
CGPoint swPoint = CGPointMake((self.mapView.bounds.origin.x), (mapView.bounds.origin.y + mapView.bounds.size.height));

//Then transform those point into lat,lng values
CLLocationCoordinate2D neCoord;
neCoord = [mapView convertPoint:nePoint toCoordinateFromView:mapView];
CLLocation *neLocation = [[CLLocation alloc] initWithLatitude:neCoord.latitude longitude:neCoord.longitude];

CLLocationCoordinate2D swCoord;
swCoord = [mapView convertPoint:swPoint toCoordinateFromView:mapView];
CLLocation *swLocation = [[CLLocation alloc] initWithLatitude:swCoord.latitude longitude:swCoord.longitude];

El problema es que me gustaría que el zoom del mapa a ser animado. Sin embargo, cuando me puse la setRegion: animado a SÍ, me acaban de obtener las coordenadas del mapa cuando se amplía la salida (es decir, antes de que se complete la animación). ¿Hay alguna manera de obtener una señal de que la animación se hace?

Publicado el 17/01/2010 a las 20:19
fuente por usuario
En otros idiomas...                            


2 respuestas

votos
21

Nunca utilizado MapKit pero el MKMapViewDelegate tiene un método mapView:regionDidChangeAnimated:que parece ser lo que estás buscando.

Respondida el 17/01/2010 a las 20:38
fuente por usuario

votos
5

Sé que esto es muy antigua, pero por si acaso alguien más viene mediante la búsqueda de una respuesta, esto es una alternativa.

Lo bueno de esta versión es que se puede ejecutar una animación de finalización en el momento exacto de la primera de ellas es completa en vez de adivinar / hardcoding que en el método de devolución de llamada desde el que se llama de inmediato.

[MKMapView animateWithDuration:1.0 animations:^{
    [mapView setRegion:mapRegion animated:YES];
} completion:^(BOOL finished) {
    [UIView animateWithDuration:1.0 animations:^{
        self.mapDotsImageView.alpha = 1.0;
    }];
}];

o solo

// zoom in...
let km3:CLLocationDistance = 3000
let crTight = MKCoordinateRegionMakeWithDistance(location.coordinate, km3, km3)
MKMapView.animate(withDuration: 1.0, animations: { self.theMap.region = crTight })
Respondida el 29/07/2016 a las 21:23
fuente por usuario

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more