2012-11-01 89 views
0

在我的新ios應用程序的不同位置顯示小號MKMapView,其中滾動和用戶交互被禁用。每張地圖都會有一個自定義註釋。MKMapView,預加載註釋

如截圖所示,一切都很好看。但是,有一個我不喜歡的小行爲。當加載包含MKMapView的視圖或單元格時,地圖會立即顯示,但在向其添加註釋之前存在一個小的延遲。我認爲這是由於註釋工作的方式(如UITableView)。

因爲我的地圖總是會包含一個註釋,有沒有辦法在地圖實際出現在屏幕上之前強制它在地圖上預先加載。我不希望這個小的延遲真的很煩人,而MKMapView被包含在tableview單元格中,它在滾動時被重新加載。 歡迎任何其他想法。

感謝

iphone screenshot

回答

0

我沒有怎麼測試,但怎麼樣設置:

myPinView.animatesDrop = NO; 
在viewForAnnotation委託

,因爲默認情況下它被設置爲YES值。

0

我不知道你在代碼中做了什麼,但也許它可以幫助你。

- (MKAnnotationView *)mapView:(MKMapView *)mv viewForAnnotation:(id <MKAnnotation>)annotation 
{ 
MKPinAnnotationView* pv = (MKPinAnnotationView*)[mv dequeueReusableAnnotationViewWithIdentifier:reuse]; 
    if (pv == nil) 
    { 
     pv = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuse] autorelease]; 
     [pv setAnimatesDrop:YES]; // replace this line with the following line 
     [pv setAnimatesDrop:NO]; 
    } 

    [pv setAnnotation:annotation]; 

    return pv; 
} 
0

你爲什麼不只是設置初始化,然後加入您的註釋後,這個方法會被觸發時可以隱藏你的MapView:

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views 
{ 
    // reveal map 
    mapView.hidden = NO; 

    // ----------------------------------------------------------------- 
    // ALTERNATIVE WAY TO SHOW MAP VIEW WITH SMOOTH FADE IN 
    // 
    // if you want you can even animate the fading in of the 
    // note: this means you need to remove the above line 
    // and you also need to set mapView.alpha = 0 during initialsation 
    // instead of using mapView.hidden = YES 
    // ----------------------------------------------------------------- 
    [UIView animateWithDuration:0.5 animation:^{ 
     mapView.alpha = 1; 
    }]; 
} 

(參考:http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKMapViewDelegate_Protocol/MKMapViewDelegate/MKMapViewDelegate.html#//apple_ref/occ/intfm/MKMapViewDelegate/mapView:didAddAnnotationViews :)