定位自定义MKAnnotationView

9

我创建了一个自定义的MKAnnoationView,代码如下:

- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
    MKAnnotationView* customPinView = [[MKAnnotationView alloc]
                                           initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier];

    UIImage *pinImage = [PowerPlantAnnotation getAnnotationImageForEnergySource:((PowerPlantAnnotation*)annotation).energySource];
    customPinView.image = pinImage;
    return customPinView;
}

我已经将我想要的图片放置在大致正确的位置,但还不够完美。我的图像如下:

enter image description here

我希望水滴形状的底部指向我的注释地图坐标,就像标准的引脚视图指向地图坐标一样。我该怎么做呢?目前,看起来我的图像更像是位于地图坐标中心。

1个回答

15

默认情况下,注释视图中心被放置在注释坐标处。要调整视图位置,请设置其属性:centerOffset

annotationView.centerOffset = CGPointMake(0.0f, -annotationViewHeight/2);

在这种情况下,视图的中心对齐于精确的坐标位置。引脚的底部应该位于坐标上以保证准确性。 - carbonr

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接