gpt4 book ai didi

ios - 定位自定义 MKAnnotationView

转载 作者:可可西里 更新时间:2023-11-01 03:06:59 26 4
gpt4 key购买 nike

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com