Come faccio a sapere quando MKMapview setregion: animato: è finito?

voti
18

Voglio impostare una regione sul mio MKMapView e poi trovare le coordinate corrispondenti all'angolo NE e SW della mappa.

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

Il problema è che vorrei la mappa dello zoom per essere animato. Tuttavia, quando ho impostato il setregion: animato su YES, finisco per ottenere le coordinate dalla mappa quando è ingrandita via d'uscita (vale a dire, prima che l'animazione è stata completata). C'è un modo per ottenere un segnale che l'animazione è fatto?

È pubblicato 17/01/2010 alle 20:19
fonte dall'utente
In altre lingue...                            


2 risposte

voti
21

Mai usato MapKit ma il MKMapViewDelegate ha un metodo mapView:regionDidChangeAnimated:che sembra essere quello che stai cercando.

Risposto il 17/01/2010 a 20:38
fonte dall'utente

voti
5

So che questo è super vecchio, ma solo nel caso in cui nessun altro arriva, cercando una risposta, ecco un'alternativa.

La cosa bella di questa versione è che è possibile eseguire un'animazione di completamento nel momento esatto il primo è completa, invece di indovinare / hardcoding nel metodo di callback dal momento che è chiamato subito.

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

o semplicemente

// zoom in...
let km3:CLLocationDistance = 3000
let crTight = MKCoordinateRegionMakeWithDistance(location.coordinate, km3, km3)
MKMapView.animate(withDuration: 1.0, animations: { self.theMap.region = crTight })
Risposto il 30/07/2016 a 00:23
fonte dall'utente

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