我在 iOS 中的地图上放置了自定义标记,但我遇到了一个问题,即当用户捏合以放大和缩小时,标记不会锚定到它们应该定位的位置。这是添加标记的代码...
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
MarkerVO *thisMarker = (MarkerVO*)annotation;
MKAnnotationView *pin = (MKAnnotationView *) [map dequeueReusableAnnotationViewWithIdentifier:[thisMarker commaSeparatedCoordinate]];
if (!pin) {
pin = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:[thisMarker commaSeparatedCoordinate]] autorelease];
[pin setImage:[UIImage imageNamed:@"pin_tick.png"]];
[pin setCenterOffset:CGPointMake(0, -23)];
[pin setCanShowCallout:YES];
}
return pin;
}
所以是的,刻度标记显示正常,但在缩放时,它只是四处移动。例如,它可能在近距离变焦时就在原地,但远距离变焦最终会在海中!我知道为什么会发生这种情况,但是即使没有 setCenterOffset 线,它仍然会发生。
任何想法都会很棒。