Własne obrazy annotationView powrócić do szpilek po kliknięciu

głosy
2

Ja wyświetlania niestandardowych obrazów na mapie (zamiast kołków domyślnych) stosując poniższy kod. Jednak, kiedy dotknąć elementu (i pojawia się objaśnienie), obraz powraca do domyślnego czerwonym pin. Jak mogę zachować mój własny obraz, nawet gdy wyświetlany jest objaśnienie?

- (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];
}
Utwórz 05/04/2010 o 00:08
źródło użytkownik
W innych językach...                            


2 odpowiedzi

głosy
5

Znalazłem uzależniając pinAnnotation MKAnnotationView raczej niż MKPinAnnotationView, mam pożądanego rezultatu. Obraz nie włącza się już kołkiem

    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"];
Odpowiedział 23/11/2010 o 08:47
źródło użytkownik

głosy
0

Trzeba użyć podrzędny zamiast właściwości obrazu. Ten kod succssfully rozwiązuje problem dla mnie:

    UIImage * image = [UIImage imageNamed:@"blue_pin.png"];
    UIImageView *imageView = [[[UIImageView alloc] initWithImage:image] autorelease];
    [annView addSubview:imageView];
Odpowiedział 20/05/2010 o 12:53
źródło użytkownik

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