Chr*_*her 3 cocoa-touch mkmapview ios
我在我的应用程序中有一个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;
}
Run Code Online (Sandbox Code Playgroud)
它工作正常,自定义图像也正常显示,但当我捏mapView以放大/缩小地图时,我注意到自定义图像在地图上失去了准确性.请看下面的图片.
https://www.dropbox.com/s/irrgmohppf08fzr/image1.png 此图显示引脚位于此位置,非常准确.
https://www.dropbox.com/s/vvlr4ckk6molqd7/image2.png 缩小mapView后,针脚穿过街道,显示该地址在湖中....
(对不起链接,因为由于声誉不足而无法发布图片.)
有人可以帮我这个吗?我的图像是44x44,我也尝试设置引脚的centerOffset,它无法在所有缩放级别动态解决这个问题.
这只是错误的中心偏移.但请注意,中心偏移取决于您使用的注释视图的类型.我不知道是什么RMAnnotationView.如果它是一个子类MKAnnotationView,centerOffset应该是CGPointMake(0, -imageHeight / 2).
| 归档时间: |
|
| 查看次数: |
851 次 |
| 最近记录: |