2012-12-07 87 views
0

在我的地圖視圖中,我將地圖設置爲打開,然後延遲2秒,地圖放大以顯示我的mkannotation,我一直在試圖做的動作是將pin一旦視圖完全放大,但一直未能實現這一點。如何添加延遲到mkannotation pin drop

所以基本上我想添加一個延遲到註釋+引腳被丟棄在我的位置。

我該怎麼做?

代碼我有什麼替代目前在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]; 
} 

回答

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; 
    } 
} 
+0

不太明白你... – holtii

+0

你有什麼問題嗎? – Craig

+0

我的mapview延遲工作,然後它放大隻是我想要的,問題是我想延遲引腳刪除,我試圖把它在自己的方法,但它沒有奏效。 – holtii