annotationView imágenes personalizadas revierten a los pines cuando se hace clic

votos
2

Estoy mostrando imágenes personalizadas en un mapa (en lugar de los pasadores por defecto) con el siguiente código. Sin embargo, cuando toco en un elemento (y aparece la leyenda), la imagen vuelve a la clavija roja por defecto. ¿Cómo puedo mantener la imagen que mi costumbre, incluso cuando aparece la llamada?

- (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];
}
Publicado el 05/04/2010 a las 00:08
fuente por usuario
En otros idiomas...                            


2 respuestas

votos
5

He encontrado al hacer que el pinAnnotation un MKAnnotationView en lugar de un MKPinAnnotationView, me dieron el resultado deseado. La imagen no se convierta en un alfiler más

    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"];
Respondida el 23/11/2010 a las 08:47
fuente por usuario

votos
0

Es necesario utilizar una vista secundaria en lugar de la propiedad de la imagen. Este código resuelve el problema succssfully para mí:

    UIImage * image = [UIImage imageNamed:@"blue_pin.png"];
    UIImageView *imageView = [[[UIImageView alloc] initWithImage:image] autorelease];
    [annView addSubview:imageView];
Respondida el 20/05/2010 a las 12:53
fuente por usuario

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