我在MKMapView
上显示了几个自定义注释视图,当用户点击其中一个时,我将区域更改为居中:
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
if ([view.annotation isKindOfClass:[CustomAnnotation class]]) {
double miles = 2.5;
double scalingFactor = ABS(cos(2 * M_PI * lat / 360.0));
MKCoordinateSpan span;
span.latitudeDelta = miles/69.0;
span.longitudeDelta = miles/(scalingFactor * 69.0);
MKCoordinateRegion region;
region.span = span;
region.center = self.coordinates;
[self.mapView setRegion:region animated:YES];
}
}
我看到,当注释已经或多或少地显示在地图的中心时,会显示标注,但是当我点击靠近地图边界的注释并且该区域必须“更多“。我尝试在区域设置动画结束后选择注释:
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{
for (id annotation in self.mapView.annotations) {
if ([annotation isKindOfClass:[CustomAnnotation class]]) {
if (((CustomAnnotation *)annotation).id == self.selectedAnnotation.id) {
[self.mapView selectAnnotation:annotation animated:YES];
}
}
}
}
但是标注没有显示出来。如果我在点击时不以编程方式更改区域,则会显示所有标注。我怎么能解决这个问题?
由于