我的应用程序中有一个 mapView,我正在为 MKAnnotationView 使用我自己的图像,这是 pin 图像。这是我设置它的代码。
-(RMAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(RentPin *)annotation{
static NSString *identifier = @"MyLocation";
if ([annotation isKindOfClass:[RentPin class]]) {
RMAnnotationView *annotationView = (RMAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if(annotationView == nil){
annotationView = [[RMAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
annotationView.enabled = YES;
annotationView.canShowCallout = NO;
annotationView.image = [UIImage imageNamed:@"home44.png"];
annotationView.centerOffset = CGPointMake(-10, -10);
}else{
annotationView.annotation = annotation;
}
return annotationView;
}
return nil;
}
它工作正常,自定义图像也能正常显示,但是当我捏住 mapView 放大/缩小 map 时,我注意到自定义图像在 map 上失去了准确性。请看下面的图片。
https://www.dropbox.com/s/irrgmohppf08fzr/image1.png 此图显示大头针位于此位置,非常准确。
https://www.dropbox.com/s/vvlr4ckk6molqd7/image2.png 在我缩小 mapView 后,图钉穿过街道并显示这个地址在湖中....
(抱歉链接,因为信誉不足我无法发布图片。)
有人可以帮我解决这个问题吗?我的 pin 图像是 44x44,我也尝试设置 pin 的 centerOffset,它无法在所有缩放级别动态解决这个问题。
最佳答案
这只是错误的中心偏移。但请注意,中心偏移量取决于您使用的注释 View 类型。我不知道 RMAnnotationView
是什么。如果它是 MKAnnotationView
的子类,则 centerOffset
应该是 CGPointMake(0, -imageHeight/2)
。
关于ios - 放大/缩小 map 时,MKMapView 自定义图钉图像失去准确性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24276447/