我已經實現了一個地圖應用程序,其中我有當前位置的顯示引腳動畫。當我點擊引腳時,註釋視圖將打開。但是我想顯示 註釋視圖,而不用點擊pin.Is如果可能的話,那麼請給我一些想法。如何顯示註釋視圖,而無需在mapview中點擊圖釘?
在此先感謝。
我已經實現了一個地圖應用程序,其中我有當前位置的顯示引腳動畫。當我點擊引腳時,註釋視圖將打開。但是我想顯示 註釋視圖,而不用點擊pin.Is如果可能的話,那麼請給我一些想法。如何顯示註釋視圖,而無需在mapview中點擊圖釘?
在此先感謝。
我們可以在沒有點擊的情況下顯示註釋。使用下面的代碼:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
static NSString *identifier = @"Pin";
MKPinAnnotationView *pin = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
pin.canShowCallout = YES;
[pin setSelected:YES animated:NO];
return [pin autorelease];
}
你只需要找到您要選擇並調用-setSelected:animated:
您MKAnnotationView實例。
例如,您可以循環您的的MKMapView像這樣的註解:
for (YOURCLASSHERE *a in mapView.annotations) {
// Your current position (if shown) is an annotation as well. Thus check for the right class!
if ([a isKindOfClass:[YOURCLASSHERE class]]) {
// insert some smart if statement here, if you have multiple annotations!
[[mapView viewForAnnotation:a] setSelected:YES animated:YES];
}
}
YOURCLASSHERE是你的類,它實現MKAnnotation
協議。
當然,如果你已經知道你的annotationView,循環是多餘的。
感謝它的工作 – JohnWhite 2010-12-07 09:28:35
試用:
看來,[mapView selectAnnotation:annotation animated:YES]
工作過。
希望這會有所幫助。
您的代碼中存在內存泄漏,並且絕對不是實施委託方法的推薦方式。出於性能原因,您將需要重新使用現有的annotationView。 – 2010-12-07 09:19:10