2011年6月16日木曜日

MKMapViewで、addAnnotation する時に viewForAnnotation が呼び出される

[mapview addAnnotation:annotation];

addAnnotation する時に viewForAnnotationが呼び出される mapview のdelegate   viewForAnnotationです。


- (MKAnnotationView*)mapView:(MKMapView*)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
NSLog(@"viewForAnnotation");
// if (annotation == mapView.userLocation) return nil;
// ここでnilを返したとすると、ピンがAnnotationに使われる
// 細かい調整は以下

MKPinAnnotationView *annotationView = [[MKPinAnnotationView allocinitWithAnnotation:annotation reuseIdentifier:@"test"];
// [annotationView setPinColor:MKPinAnnotationColorGreen];
// [annotationView setAnimatesDrop:YES];

[annotationView setCanShowCallout:YES];// > 矢印を出すか出さないか
[annotationView setRightCalloutAccessoryView:[UIButton buttonWithType:UIButtonTypeDetailDisclosure]];
//UIImage *pinImage = [UIImage imageNamed:@"pin-image.png"];
//[annotationView setImage:pinImage];
annotationView.annotation = annotation;
return annotationView;
}


> を押すと  calloutAccessoryControlTapped 呼び出されます。

- (void) mapView:(MKMapView*)_mapView annotationView:(MKAnnotationView*)annotationView calloutAccessoryControlTapped:(UIControl*)control {  
NSLog(@"タップしたときの処理 ");
// タップしたときの処理  
// annotationView.annotation でどのアノテーションか判定可能  

0 件のコメント: