ios - 定位自定义 MKAnnotationView

标签 ios mkannotation mkannotationview mapkit

我创建了一个自定义 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

我希望泪滴的底部点指向我的注释 map 坐标,就像标准图钉 View 指向 map 坐标一样。我怎样才能做到这一点?目前它看起来更像是我的图像以 map 坐标为中心。

最佳答案

默认情况下,注释 View 中心位于注释坐标处。要调整 View 位置,请设置其 centerOffset属性:

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

关于ios - 定位自定义 MKAnnotationView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13848042/

相关文章:

ios - Swift - 导航栏未出现在自定义单元格的 Segue 中

ios - GoogleMobileAds (SWIFT) - 由于信号 : Segmentation fault: 11,命令失败

ios - MapView Pin 注释的问题 - 本地图缩放/平移/区域更改时 Pin 会失去颜色

ios - MapKit 中带有动态文本的引脚?

ios - 修改 iOS 7 中的 NSFetchedResultsController fetchRequest

iphone - iOS6.0及以上版本ZBar条码阅读器隐藏信息按钮的方法

iphone - setUserTrackingMode 在 MKMapView 上带有注释很慢

iphone - 掉落的图钉的动画不起作用

ios - 将 UIImage 传递给 MKPinAnnotationView 时遇到问题

swift - 如何在 map View 中更改 swift 4.0 中的图钉颜色