[英]MKMapView, pre-load annotation
在我的新ios App的不同位置顯示了小的MKMapView
在該MKMapView
中禁用了滾動和用戶交互。 每個地圖將始終具有單個自定義注釋。
如屏幕截圖所示,一切看起來都不錯。 但是,有一種我不滿意的小行為。 加載包含MKMapView
的視圖或單元格時,地圖會立即顯示,但是在向其添加注釋之前會有一點延遲。 我認為這是由於注釋的工作方式(如UITableView
)引起的。
由於我的地圖將始終只包含一個注釋,因此有一種方法可以強制在地圖實際顯示在屏幕上之前將其預先加載到地圖上。 我不想讓MKMapView
包含在tableview單元格中,而滾動時會重新加載,這真的很煩人。 任何其他想法都歡迎。
謝謝
我沒有如何測試它,但如何設置:
myPinView.animatesDrop = NO;
在您的viewForAnnotation委托中,因為默認情況下將其設置為YES值。
我不知道您在代碼中做了什么,但也許可以幫到您。
- (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;
}
您為什么不將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 :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.