Skąd mogę wiedzieć, kiedy MKMapview setRegion: animowane: zakończyła?

głosy
18

Chcę ustawić region na moim MKMapView a następnie znaleźć współrzędne odpowiadające rogu NE i SW 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];

Problemem jest to, chciałbym mapa zoom być animowane. Jednakże kiedy ustawić setRegion: animowane na TAK, to w końcu się współrzędne z mapy, gdy jest powiększony wyjścia (czyli przed animacja została zakończona). Czy istnieje jakiś sposób, aby uzyskać sygnał, że animacja jest zrobione?

Utwórz 17/01/2010 o 20:19
źródło użytkownik
W innych językach...                            


2 odpowiedzi

głosy
21

Nigdy nie używany mapkit ale MKMapViewDelegate ma metodę mapView:regionDidChangeAnimated:, która wydaje się być to, czego szukasz.

Odpowiedział 17/01/2010 o 20:38
źródło użytkownik

głosy
5

Wiem, że to bardzo stary, ale na wszelki wypadek ktoś przychodzi patrząc na odpowiedź, oto alternatywa.

Zaletą tej wersji jest to, że można uruchomić animację końca w momencie, pierwszy z nich jest pełna zamiast zgadywać / hardcoding go w metodzie zwrotnej ponieważ jeden nazywa się od razu.

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

Lub tylko

// zoom in...
let km3:CLLocationDistance = 3000
let crTight = MKCoordinateRegionMakeWithDistance(location.coordinate, km3, km3)
MKMapView.animate(withDuration: 1.0, animations: { self.theMap.region = crTight })
Odpowiedział 30/07/2016 o 00:23
źródło użytkownik

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