Comment puis-je savoir quand MKMapview setRegion: animation: a terminé?

voix
18

Je veux mettre une région sur mon MKMapView puis trouver les coordonnées correspondant à l'angle nord-est et sud-ouest de la carte.

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

Le problème est que je voudrais être animé le zoom de la carte. Cependant, quand je mets le setRegion: animé OUI, je finis par obtenir les coordonnées de la carte quand il est zoomée sortie (avant l'animation est terminée). Est-il possible d'obtenir un signal que l'animation se fait?

Créé 17/01/2010 à 20:19
source utilisateur
Dans d'autres langues...                            


2 réponses

voix
21

Jamais utilisé MapKit mais le MKMapViewDelegate a une méthode mapView:regionDidChangeAnimated:qui semble être ce que vous cherchez.

Créé 17/01/2010 à 20:38
source utilisateur

voix
5

Je sais que c'est super vieux, mais juste au cas où quelqu'un d'autre vient en cherchant une réponse, voici une alternative.

La bonne chose à propos de cette version est que vous pouvez exécuter une animation d'achèvement au moment précis où la première est complète au lieu de deviner / hardcoding dans la méthode de rappel depuis que l'on est appelé tout de suite.

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

ou juste

// zoom in...
let km3:CLLocationDistance = 3000
let crTight = MKCoordinateRegionMakeWithDistance(location.coordinate, km3, km3)
MKMapView.animate(withDuration: 1.0, animations: { self.theMap.region = crTight })
Créé 30/07/2016 à 00:23
source utilisateur

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