1
我正在使用MKMapView,其中我放置了某個地址的引腳。我需要這樣做:如果我觸摸的針不應該顯示標註和觸摸事件應該打電話。任何人都可以幫助我做到這一點?如何獲取沒有標註選項的MapPin tap事件?
我正在使用MKMapView,其中我放置了某個地址的引腳。我需要這樣做:如果我觸摸的針不應該顯示標註和觸摸事件應該打電話。任何人都可以幫助我做到這一點?如何獲取沒有標註選項的MapPin tap事件?
在mapView:viewForAnnotation:
委託方法,將canShowCallout
屬性設置爲NO並使用mapView:didSelectAnnotationView:
來檢測觸摸:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
static NSString *annotIdentifier = @"annot";
MKPinAnnotationView *pav = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:annotIdentifier];
if (!pav)
{
pav = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annotIdentifier] autorelease];
pav.canShowCallout = NO;
}
else
{
pav.annotation = annotation;
}
return pav;
}
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
NSLog(@"annotation touched: %@", view.annotation.title);
}
確保地圖視圖的委託屬性的設置,否則這些方法將不會被調用。