2012-12-06 49 views
4

我在其他應用程序中看到了它exmaple ios 6 starbucks,當我的mapview打開時,我希望它顯示整個英國/英國島嶼的區域,然後我希望它放大到我指定的位置區域點。當mapview打開時,動畫縮放到位置/地圖地標iOS

更新的代碼:

- (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 1.5 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]; 

[self performSelector:@selector(selectAnnotation) 
      withObject:nil 
      afterDelay:0.5]; //will zoom in after 0.5 seconds 

} 

-(void)selectAnnotation 
{ 

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

} 

不知道它是正確的,因爲如果你想開始顯示一個區域,然後放大的誤差是此行

ann.coordinate = region.center; 

回答

11

,你必須發出兩個或更多setRegion來電,因爲setRegion本身不允許您控制起始區域或動畫的速度。

viewDidLoad,設定初始區域的span所以整個英國是可見的(嘗試10.0代替0.15增量)。您還可以爲初始區域設置animatedNO

隨後的viewDidLoad結束前,安排放大到在幾秒鐘後執行:

- (void)viewDidLoad 
{ 
    ... 

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

zoomInToMyLocation方法可能是這樣的:

-(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.15f; 
    region.span.latitudeDelta = 0.15f; 
    [mapView setRegion:region animated:YES]; 
} 


一件事在使用performSelector時,您可能必須注意在呼叫計劃運行之前,如果視圖已關閉或解除分配,則取消掛起的呼叫。例如,如果用戶在加載後兩秒鐘關閉視圖。三秒鐘後,預定的方法仍可能會被調用,但會在視圖消失後崩潰。爲了避免這種情況,取消viewWillDisappear:任何未決的執行或酌情:

[NSObject cancelPreviousPerformRequestsWithTarget:self]; 
+0

優秀感謝我將努力實現這一點有什麼方法我把第一組區域中,目前收到了未申報的錯誤:) – holtii

+0

... – holtii

+0

在viewDidLoad中,你已經擁有了它。只是改變跨度。 – Anna

0
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } }; 
region.center.latitude = Your Latitude ; 
region.center.longitude = Your Longitude; 
region.span.longitudeDelta = 0.01f; 
region.span.latitudeDelta = 0.01f; 
[map setRegion:region animated:YES]; 
[map addAnnotation:ann]; 
相關問題