【发布时间】:2012-11-21 11:23:35
【问题描述】:
常规注解图钉的原点在底部中间 所以,大头针总是指向同一个地方。
但是当我添加我的自定义图像时,它的原点是图像的中心,所以每次放大或缩小,我的图像底部都会指向不同的位置。
这里我的图钉应该指向巴黎的中心但是
但是当我放大时,我的图钉底部没有指向巴黎的中心。
我正在尝试使用 CGRect.origin,但没有得到任何有用的信息。
这是我的代码:
- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MKAnnotationView * customPinView = [[MKAnnotationView alloc] init];
UIImage * img = [UIImage imageNamed:@"waterPin.png"] ;
CGRect resizeRect;
resizeRect.size.height = 40;
resizeRect.size.width = 40;
resizeRect.origin = (CGPoint){0.0f, 0.0f};
UIGraphicsBeginImageContext(resizeRect.size);
[img drawInRect:resizeRect];
UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
customPinView.image = resizedImage;
return customPinView;
}
【问题讨论】:
-
如果你能发布一些代码??
-
注释设置的坐标(纬度/经度)到底是多少?尝试设置
customPinView.centerOffset来调整图像偏移(但我会先验证坐标)。此外,您应该使用 initWithAnnotation 而不是只为 MKAnnotationView 使用 init。 -
不不,坐标是对的,但就是那个小属性,centerOffset,非常感谢
-
您好,您能告诉我如何将默认引脚替换为“waterPin.png”。
-
在上面的代码中,只要获取你的图片,并将其分配给注解的image属性 img = .....; pin.image = img;
标签: ios mapkit mkannotationview