gpt4 book ai didi

iphone - 我怎样才能知道MKMapview何时setRegion :animated: has finished?

转载 作者:行者123 更新时间:2023-12-03 18:17:48 26 4
gpt4 key购买 nike

我想在我的MKMapView上设置一个区域,然后找到与 map 的东北角和西南角对应的坐标。

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

问题是我希望 map 缩放具有动画效果。但是,当我将 setRegion:animated 设置为 YES 时,我最终会在 map 缩小时(即在动画完成之前)从 map 中获取坐标。有没有办法获得动画完成的信号?

最佳答案

从未使用过mapkit,但MKMapViewDelegate有一个方法 mapView:regionDidChangeAnimated: 看起来正是您正在寻找的内容。

请注意,mapView:regionDidChangeAnimated: 每次发生变化时都会被调用,例如当用户移动 map 时。

关于iphone - 我怎样才能知道MKMapview何时setRegion :animated: has finished?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2082269/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com