在MKMap中设置区域后,区域中的跨度自动变为两次

时间:2012-04-11 11:33:34

标签: objective-c mkmapview mkcoordinateregion

我今天下午遇到了这个问题。 我不希望有不同的跨度......

我的代码是

- (IBAction)arrowClicked:(id)sender
{
UIButton *button = (UIButton *)sender;
for (Annotation *a in self.mapView.annotations) {
    if (a.tag==button.tag-800) {
        MKCoordinateRegion region = self.mapView.region;
        region.center = a.coordinate;
        region.span = span;
        NSLog(@"%f,%f",region.span.longitudeDelta, region.span.longitudeDelta);
        NSLog(@"%i",a.tag);
        NSLog(@"arrowClicked1  %f,%f",self.mapView.region.span.longitudeDelta, self.mapView.region.span.longitudeDelta);
        NSLog(@"arrowClicked1  %f,%f",region.span.longitudeDelta, region.span.longitudeDelta);
        [self.mapView setRegion:region animated:YES];
        NSLog(@"arrowClicked2  %f,%f",self.mapView.region.span.longitudeDelta, self.mapView.region.span.longitudeDelta);
        [self.mapView selectAnnotation:a animated:NO];
        break;
    }
}
}

- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated
{
NSLog(@"will changed");
for (UIImageView *arrow in self.mapView.subviews) {
    if (arrow.tag>=800) {
        [arrow removeFromSuperview];
    }
}
NSLog(@"regionWillChangeAnimated  %f,%f",self.mapView.region.span.longitudeDelta, self.mapView.region.span.longitudeDelta);
}

,日志是

2012-04-11 20:23:46.471 SFMap[4113:11603] 103
2012-04-11 20:23:46.471 SFMap[4113:11603] arrowClicked1  0.109863,0.109863
2012-04-11 20:23:46.472 SFMap[4113:11603] arrowClicked1  0.109863,0.109863
2012-04-11 20:23:46.472 SFMap[4113:11603] will changed
2012-04-11 20:23:46.472 SFMap[4113:11603] regionWillChangeAnimated  0.109863,0.109863
2012-04-11 20:23:46.472 SFMap[4113:11603] arrowClicked2  0.219727,0.219727

我发现这个问题发生在annotationList的最后一个注释上。

有人可以解雇我吗? 感谢~~

1 个答案:

答案 0 :(得分:1)

跨度变化似乎正常:Why MKCoordinateSpan changes?

如果您只是删除以下行,它将始终保持初始范围:

span = self.mapView.region.span;