如何为mkannotation pin drop添加延迟

时间:2012-12-07 15:23:42

标签: ios6 mkmapview mkannotation

在我的地图视图中,我将地图设置为打开,然后延迟2秒,地图放大以显示我的mkannotation,我一直尝试做的是在视图完全放大后动画放下引脚,但未能实现这一点。

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

我该怎么做?

编码我目前在ViewDidLoad中的位置,mkannotation的代码在void - 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];
}

1 个答案:

答案 0 :(得分: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;
    }
}