2010-01-17 28 views
18

Tôi muốn đặt một vùng trên MKMapView và sau đó tìm tọa độ tương ứng với góc NE và SW của bản đồ.Làm cách nào để biết khi nào MKMapview setRegion: hoạt ảnh: đã hoàn tất?

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

Vấn đề là tôi muốn thu phóng bản đồ được làm động. Tuy nhiên, khi tôi đặt setRegion: animated thành YES, tôi sẽ nhận được tọa độ từ bản đồ khi nó được phóng to ra (tức là, trước khi hoạt ảnh được hoàn thành). Có cách nào để có được một tín hiệu rằng các hình ảnh động được thực hiện?

Trả lời

21

Không bao giờ sử dụng bản đồ nhưng MKMapViewDelegate có phương thức mapView:regionDidChangeAnimated: có vẻ là những gì bạn đang tìm kiếm.

+0

ngốc tôi, đó là trong giao thức đại biểu không phải là MKMapView riêng của mình. Tôi biết tôi đã nhìn thấy nó ở đâu đó ... cảm ơn: D – deadroxy

4

Tôi biết điều này là siêu cũ, nhưng chỉ trong trường hợp bất cứ ai khác đến bằng cách tìm kiếm câu trả lời, đây là một thay thế.

Điều thú vị về phiên bản này là bạn có thể chạy một hoạt ảnh hoàn thành tại thời điểm chính xác mà người đầu tiên hoàn thành thay vì đoán/mã hóa nó trong phương thức gọi lại vì nó được gọi ngay lập tức.

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

hoặc chỉ

// zoom in... 
let km3:CLLocationDistance = 3000 
let crTight = MKCoordinateRegionMakeWithDistance(location.coordinate, km3, km3) 
MKMapView.animate(withDuration: 1.0, animations: { self.theMap.region = crTight }) 
Các vấn đề liên quan