Подтвердить что ты не робот

Как узнать, когда MKMapview setRegion: анимированный: закончен?

Я хочу установить область на моем MKMapView, а затем найти координаты, соответствующие NE и SW углу карты.

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

Проблема в том, что я хотел бы, чтобы масштабирование карты было анимировано. Однако, когда я устанавливаю setRegion: анимированный YES, я получаю координаты с карты, когда он приближается (т.е. до завершения анимации). Есть ли способ получить сигнал о том, что анимация выполнена?

4b9b3361

Ответ 1

Никогда не использовался mapkit, но MKMapViewDelegate имеет метод mapView:regionDidChangeAnimated:, который выглядит так, как вы ищите.

Ответ 2

Я знаю, что это супер старый, но на всякий случай кто-то приходит, ища ответ, вот альтернатива.

Приятная вещь в этой версии заключается в том, что вы можете запускать анимацию завершения в тот момент, когда первая будет завершена, вместо того, чтобы угадывать/кодировать ее в методе обратного вызова, так как тот вызывается сразу.

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

или просто

// zoom in...
let km3:CLLocationDistance = 3000
let crTight = MKCoordinateRegionMakeWithDistance(location.coordinate, km3, km3)
MKMapView.animate(withDuration: 1.0, animations: { self.theMap.region = crTight })