0

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;
}

そうです、目盛りマーカーは「OK」と表示されますが、ズームでは動き回るだけです。たとえば、ズームを閉じるとその場で正しい可能性がありますが、ズームアウトすると海に出てしまいます。なぜこれが起こっているのかがわかりますが、setCenterOffset行がなくてもまだ起こっています。

どんなアイデアでも素晴らしいでしょう。

4

1 に答える 1

1

pinがデキューからnilを返さない場合は、pin.annotationをannotationに設定してみてください。

コードが各注釈に一意の識別子を設定しているように見えても、再利用されたビューは何らかの形で異なる注釈からのものである可能性があります(どのような場合でもお勧めしません)。

于 2011-05-29T17:13:33.160 に答える