0

我们应该这样做吗- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{

是否有一些关于正确使用的示例代码

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{
4

1 回答 1

1

是的,你可以在viewForAnnotation中做到这一点:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{        
    MKAnnotationView *annotationView = (MKAnnotationView *) [_mapView dequeueReusableAnnotationViewWithIdentifier:@"myIdentifier"];
    if (annotationView == nil) 
    {
        annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
    } 
    else 
    {
        annotationView.annotation = annotation;
    }
    annotationView.image = [UIImage imageNamed:@"myPinImage.png"];
    // set your offset here
    annotationView.centerOffset = CGPointMake(offsetX, offsetY);
    return annotationView;
} 
于 2012-10-31T01:56:28.193 回答