Jak mohu vědět, kdy MKMapview setRegion: animovaný: dokončil?

hlasů
18

Chci nastavit region na svém MKMapView a pak najít souřadnice odpovídající SV a JZ rohu mapy.

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

Problém je v tom bych chtěl mapa zoom být animovaný. Nicméně, když jsem nastavit setRegion: animovaný YES, jsem nakonec dostat souřadnic z mapy, když je to zvětšeném cesta ven (tedy předtím, než se animace dokončena). Je nějaký způsob, jak se dostat signál, že animace se provádí?

Položena 17/01/2010 v 20:19
zdroj uživatelem
V jiných jazycích...                            


2 odpovědí

hlasů
21

Nikdy nepoužíval mapkit ale MKMapViewDelegate má metodu mapView:regionDidChangeAnimated:, která vypadá, že je to, co hledáte.

Odpovězeno 17/01/2010 v 20:38
zdroj uživatelem

hlasů
5

Vím, že to je super starý, ale jen v případě, že někdo jiný přijde tím, že hledá odpověď, zde je alternativa.

Zajímavou věcí na této verzi je, že můžete spustit dokončení animace přesně v okamžiku, kdy první z nich je kompletní namísto hádání / napevno ji v metodě zpětné volání, protože, že jeden se jmenuje hned.

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

nebo prostě

// zoom in...
let km3:CLLocationDistance = 3000
let crTight = MKCoordinateRegionMakeWithDistance(location.coordinate, km3, km3)
MKMapView.animate(withDuration: 1.0, animations: { self.theMap.region = crTight })
Odpovězeno 30/07/2016 v 00:23
zdroj uživatelem

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