iPhone自定义锁屏密码位置问题

7
我有一个应用程序,使用iPhone地图工具包。它显示一组标准标记。现在我切换到自定义图像的标记(使用MKMapViewDelegate)。
问题是自定义标记没有正确地居中 - 自定义标记指向靠近原始位置的位置。
问题是iPhone如何处理自定义标记。例如:让我们有一个50x50像素的图像标记。我们有全球坐标(长,纬度):XY
iPhone将如何居中图像?
谢谢
2个回答

9
如果你将自定义图片赋值给image属性,当注释显示时,图片将居中显示在目标地图坐标上。如果你不想让图片居中在地图坐标上,可以使用centerOffset属性,在任意方向上水平和垂直移动中心点。因此,自定义图片仅在目标坐标的中心显示。
MKAnnotationView* aView = [[[MKAnnotationView alloc] initWithAnnotation:annotation

                                  reuseIdentifier:@"MyCustomAnnotation"] autorelease];

aView.image = [UIImage imageNamed:@"myimage.png"];

aView.centerOffset = CGPointMake(10, -20);     

来源:苹果MKMapView类参考

这个链接提供了有关如何在地图上注释位置的详细信息。

6
解决方案是在地图视图的代理中设置中心偏移量,而不是在注释视图本身中进行设置:
- (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;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接