Custom annotationView beelden terug te keren naar pinnen wanneer erop wordt geklikt

stemmen
2

Ik ben het weergeven van aangepaste afbeeldingen op de kaart (in plaats van de standaard pinnen) met behulp van de onderstaande code. Echter, toen ik tik op een item (en het bijschrift verschijnt), het beeld keert terug naar de standaard rode pen. Hoe kan ik het mijn gewoonte, zelfs wanneer het bijschrift wordt weergegeven?

- (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];
}
De vraag is gesteld op 05/04/2010 om 00:08
bron van user
In andere talen...                            


2 antwoorden

stemmen
5

Ik vond dat door het maken van de pinAnnotation een MKAnnotationView in plaats van een MKPinAnnotationView, kreeg ik het gewenste resultaat. Afbeelding niet om te zetten in een pin meer

    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"];
antwoordde op 23/11/2010 om 08:47
bron van user

stemmen
0

Je moet een subweergave gebruiken in plaats van de eigenschap afbeelding. Deze code lost succssfully het probleem voor mij:

    UIImage * image = [UIImage imageNamed:@"blue_pin.png"];
    UIImageView *imageView = [[[UIImageView alloc] initWithImage:image] autorelease];
    [annView addSubview:imageView];
antwoordde op 20/05/2010 om 12:53
bron van user

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