0

在我的地图视图中,我将地图设置为打开,然后延迟 2 秒,地图会放大以显示我的 mkannotation,我一直在尝试做的是在视图完全放大后动画针落下,但没有无法做到这一点。

所以基本上我想在我的位置放置注释+引脚添加延迟。

我该怎么做呢?

编写我当前在 ViewDidLoad 中的代码,mkannotation 的代码是无效的 - showDetails:

- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view.

[mapView setMapType:MKMapTypeStandard];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.center.latitude = 54.5;
region.center.longitude = -3.5;
region.span.longitudeDelta = 10.0f;
region.span.latitudeDelta = 10.0f;
[mapView setRegion:region animated:NO];

[self performSelector:@selector(zoomInToMyLocation)
           withObject:nil
           afterDelay:2]; //will zoom in after 2 seconds
}

-(void)zoomInToMyLocation
{
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.center.latitude = 51.502729 ;
region.center.longitude = -0.071948;
region.span.longitudeDelta = 0.19f;
region.span.latitudeDelta = 0.19f;
[mapView setRegion:region animated:YES];

[mapView setDelegate:self];

DisplayMap *ann = [[DisplayMap alloc] init];
ann.title = @"Design Museum";
ann.subtitle = @"Camberwell, London";
ann.coordinate = region.center;
[mapView addAnnotation:ann];
}
4

1 回答 1

0

如果您在设置区域之前设置了代理,您的代理将收到对mapView:regionDidChangeAnimated的调用。滚动时会调用很多次,因此您可以做的是检查地图的当前中心点,当它足够接近您的目标中心点时,您可以添加注释。

- (void)viewDidLoad
{
    [super viewDidLoad];
    [mapView setDelegate:self];
     ............
    haveAddedPin = false;
}


-(void)zoomInToMyLocation
{
    MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
    region.center.latitude = 51.502729 ;
    region.center.longitude = -0.071948;
    region.span.longitudeDelta = 0.19f;
    region.span.latitudeDelta = 0.19f;
    [mapView setRegion:region animated:YES];
}

-(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(Boolean) animated)
{
    if (haveAddedPin == false && mapView.center == the coordinates of the target you are zooming to)
    {
        DisplayMap *ann = [[DisplayMap alloc] init];
        ann.title = @"Design Museum";
        ann.subtitle = @"Camberwell, London";
        ann.coordinate = region.center;
        [mapView addAnnotation:ann];
        haveAddedPin = true;
    }
}
于 2012-12-08T04:25:42.393 回答