2

現在のユーザーの場所を示す MKMapView に移動注釈があります。その注釈用に独自の画像を設定し、見出しが見えるように回転させたいと考えています。

viewForAnnotationデリゲートには、次のものがあります。

static NSString *planeIdentifier = @"Plane";
static NSString *stationIdentifier = @"Station";
NSString *identifier;

if([[annotation title] rangeOfString:@"Plane" options:NSLiteralSearch].location == NSNotFound) {
    identifier = stationIdentifier;
}
else {
    identifier = planeIdentifier;
}

MKAnnotationView *annotationView = (MKAnnotationView *) [aMapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annotationView == nil) {
    annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
} else {
    annotationView.annotation = annotation;
}

annotationView.enabled = YES;

annotationView.canShowCallout = NO;
    annotationView.image = [UIImage imageNamed:@"airPlane.png"];

return annotationView;

インスタンス メソッドを呼び出すコードは次のとおりです。

[planeAnnotation setCoordinate:planeCoordinate];
MKAnnotationView* planeView = [self mapView:mapView viewForAnnotation:planeAnnotation];
[planeView setTransform:CGAffineTransformMakeRotation([[[self modele] udpData] getValueFor:HDING_TRUE item:DYNAMICS]*(M_PI/180))];

問題は、見出しが更新されないことです。つまり、画像が回転しません。

どんな助けでも大歓迎です!

編集: mapView にある MKAnnotationView (数百) ごとにカスタム識別子 (注釈のタイトル) を設定しようとしましたが、annotationView が常にnilであることに気付きました。つまり、実際には何もデキューされません。マップに表示している同じ MKAnnotationView を回転させていないため、これが回転しない理由だと思います。

4

1 に答える 1

4

私の質問に答えると、問題は 、MKAnnotationView を変換するときMKAnnotationView* planeView = [self mapView:mapView viewForAnnotation:planeAnnotation];にインスタンス メソッドを呼び出すのではなく、デリゲート メソッドを呼び出していたという事実にありました。MKAnnotationView* planeView = [mapView viewForAnnotation:planeAnnotation];

于 2012-07-16T21:43:14.250 に答える