我有一个使用iphone地图套件的应用程序.它显示了一组标准引脚.现在我切换到引脚的自定义图像(使用MKMapViewDelegate)
问题是自定义引脚没有居中 - 自定义引脚指向原始位置附近的位置.
问题是iphone如何使用自定义引脚.例如:让我们有50x50像素的图像.我们有全局坐标(long,lat):XY
iphone中心图片怎么样?
谢谢
如果将自定义图像分配给图像属性.显示注释时,图像将以目标地图坐标为中心显示.如果您不希望图像在地图坐标上居中,则可以使用centerOffset属性在任何方向上水平和垂直移动中心点.
因此,自定义图像仅显示在目标坐标的中心.
MKAnnotationView* aView = [[[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:@"MyCustomAnnotation"] autorelease];
aView.image = [UIImage imageNamed:@"myimage.png"];
aView.centerOffset = CGPointMake(10, -20);
Run Code Online (Sandbox Code Playgroud)
解决方案是在mapView的委托中设置中心偏移量,而不是在注释视图中设置它自己:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
static NSString* const kPinIdentifier = @"pinidentifier";
PinAnnotationView* customPinView = [[[PinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:kPinIdentifier] autorelease];
customPinView.canShowCallout = NO;
// Here !!
customPinView.centerOffset = CGPointMake(0, -21.5f);
return customPinView;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4848 次 |
| 最近记录: |