Benutzerdefinierte AnnotationView Bilder zurückkehren zu den Stiften, wenn darauf geklickt

stimmen
2

Ich Anzeige benutzerdefinierte Bilder auf einer Karte (anstelle des Standard-Pins) unter Verwendung des Codes. Allerdings, wenn ich auf ein Element tippen (und die Legende erscheint), kehrt das Bild auf den Standard roten Stift. Wie kann ich mein eigenes Bild zu halten, auch wenn die callout angezeigt werden?

- (MKAnnotationView *) mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
    MKPinAnnotationView *pinAnnotation = nil;

    if (annotation != mapView.userLocation) 
    {
        static NSString *pinID = @mapPin;
        pinAnnotation = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:pinID];
        if (pinAnnotation == nil)
            pinAnnotation = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pinID] autorelease];

        // Set the image
        pinAnnotation.image = [UIImage imageNamed:@TestIcon.png];

        // Set ability to show callout
        pinAnnotation.canShowCallout = YES;

        // Set up the disclosure button on the right side
        UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        pinAnnotation.rightCalloutAccessoryView = infoButton;

        [pinID release];
    }

    return pinAnnotation;
    [pinAnnotation release];
}
Veröffentlicht am 05/04/2010 um 00:08
quelle vom benutzer
In anderen Sprachen...                            


2 antworten

stimmen
5

Ich fand durch die pinAnnotation ein MKAnnotationView machen, anstatt eine MKPinAnnotationView, bekam ich das gewünschte Ergebnis. Bild lässt sich nicht in einen Stift mehr

    static NSString *pinID = @"mapPin";
    pinAnnotation = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:pinID];
    if (pinAnnotation == nil)
        pinAnnotation = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pinID] autorelease];

    // Set the image
    pinAnnotation.image = [UIImage imageNamed:@"TestIcon.png"];
Beantwortet am 23/11/2010 um 08:47
quelle vom benutzer

stimmen
0

Sie benötigen einen subview eher als die Bildeigenschaft zu verwenden. Dieser Code succssfully löst das Problem für mich:

    UIImage * image = [UIImage imageNamed:@"blue_pin.png"];
    UIImageView *imageView = [[[UIImageView alloc] initWithImage:image] autorelease];
    [annView addSubview:imageView];
Beantwortet am 20/05/2010 um 12:53
quelle vom benutzer

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more