MKAnnotation的自定义图像的底部位置不正确(尺寸问题)

时间:2014-06-17 08:00:21

标签: ios ios7 mkannotation mkannotationview

我有点问题。
我实施了viewForAnnotation来为地图上的图钉渲染自定义图像 但它认为图像有问题。

使用标准的电话引脚图标,它工作正常,但使用自定义图像,因为您可以看到引脚的底部不是应该的位置。

销的底部应位于红线的末端 我想必须有一些尺码问题。

有人可以告诉我在为pin创建自定义图像时应该使用什么尺寸?

enter image description here

2 个答案:

答案 0 :(得分:5)

请尝试以下代码。它使用委托方法放置一个引脚。

    - (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
    {
        MKAnnotationView *annotationView = [[MKAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"annotationReuse"];
        UIImage *pinImage = [UIImage imageNamed:@"pi-image.png"];
        annotationView.image = pinImage;
        annotationView.centerOffset = CGPointMake(0, -pinImage.size.height/2);
        return annotationView;
    }

答案 1 :(得分:3)

请参阅centerOffset

  

默认情况下,注释视图的中心点位于关联注释的坐标点。您可以根据需要使用此属性重新定位注释视图。该x和y偏移值以像素为单位测量。正偏移值向下和向右移动注释视图,而负值向上和向左移动。

相关问题