質問

デリゲート内に次のコードがあります。

     - (MKAnnotationView *)mapView:(MKMapView *)aMapView viewForAnnotation:(id <MKAnnotation>)anAnnotation 
{
    MKPinAnnotationView *pin = (MKPinAnnotationView *) [map dequeueReusableAnnotationViewWithIdentifier: @"RoutePin"];
    if (pin == nil)
    {
        if ([anAnnotation isKindOfClass:[RouteMapAnnotation class]])
        {
            RouteMapAnnotation *theAnnotation = (RouteMapAnnotation *)anAnnotation;
            if (theAnnotation.identifier == @"routePin")
            {
                //NSLog(@"TESTING PART III");
                MKPinAnnotationView *startAnnotationPin = [[MKPinAnnotationView alloc] initWithAnnotation:anAnnotation reuseIdentifier:@"RoutePin"];
                UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
                startAnnotationPin.canShowCallout = YES;
                startAnnotationPin.animatesDrop = YES;

                startAnnotationPin.rightCalloutAccessoryView = rightButton;
                startAnnotationPin.pinColor = MKPinAnnotationColorRed;
                return startAnnotationPin;
            }
            else if (theAnnotation.identifier == @"finishPin")
            {
                NSLog(@"CREATING FINISH FLAG PRIOR");
                MKPinAnnotationView *finishAnnotationPin = [[MKPinAnnotationView alloc] initWithAnnotation:anAnnotation reuseIdentifier:@"FinishPin"];
                finishAnnotationPin.canShowCallout = NO;
                finishAnnotationPin.animatesDrop = YES;
                //finishAnnotationPin.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://cdn4.iconfinder.com/data/icons/formula1/f1_png/128/checkered_flag.png"]]];
                finishAnnotationPin.image = [UIImage imageNamed:@"flag_finish"];
                return finishAnnotationPin;

            }
        }
    }
    return nil;
}

ただし、マップ上のピンの画像が表示されていません。何が足りないの?

役に立ちましたか?

解決

mkpinannotationViewの代わりにmkannotationViewを使用する必要があります。

ピン注釈はピン用です。

他のヒント

また、mkpinannotationViewは、ドラッグ中のアニメーションや3Dシャドウエフェクトなど、通常のmkannotationViewにいくつかの追加機能を提供していることに注意してください。 mkannotationViewを使用しても、これらは取得できません。

これらの組み込み機能が必要な場合は、uiimageviewを作成して、mkpinannotationViewのサブビューとして追加できます。これにより、あなたが望むもののように見える注釈が与えられます。しかし、ピンのように動作します。私はそれを使用して、ピンの頭を自分の画像に置き換えます。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top