Wie kann ich wissen, wann MKMapView setRegion: animated: fertig ist?

stimmen
18

Ich möchte eine Region auf meinem MKMapView setzen und dann die Koordinaten der Karte entsprechend den NE und SW Ecke.

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

Das Problem ist, möchte ich die Karte zoomen animiert werden. Allerdings, wenn ich die setRegion gesetzt: animierte JA, ich am Ende der Koordinaten von der Karte bekommen, wenn sie Art und Weise vergrößert oder verkleinert ist (dh bevor die Animation abgeschlossen ist). Gibt es eine Möglichkeit, ein Signal zu erhalten, dass die Animation fertig ist?

Veröffentlicht am 17/01/2010 um 20:19
quelle vom benutzer
In anderen Sprachen...                            


2 antworten

stimmen
21

Nie verwendet MapKit aber die MKMapViewDelegate hat ein Verfahren , mapView:regionDidChangeAnimated:das zu sein , was sucht nach dem Sie suchen.

Beantwortet am 17/01/2010 um 20:38
quelle vom benutzer

stimmen
5

Ich weiß, das Super alt ist, aber nur für den Fall, dass jemand anderes kommt durch eine Antwort suchen, ist hier eine Alternative.

Das Schöne an dieser Version ist, dass Sie die erste abgeschlossen ist eine Abschluss-Animation am genauen Moment laufen können, anstatt zu raten / es in der Callback-Methode hartzucodieren da, dass man sofort aufgerufen wird.

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

oder nur

// zoom in...
let km3:CLLocationDistance = 3000
let crTight = MKCoordinateRegionMakeWithDistance(location.coordinate, km3, km3)
MKMapView.animate(withDuration: 1.0, animations: { self.theMap.region = crTight })
Beantwortet am 30/07/2016 um 00:23
quelle vom benutzer

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