Egyedi annotationView képek visszatér csapok Kattintáskor

szavazat
2

Én megjelenítésére egyéni képeket a térképen (az alapértelmezett helyett tüskék) alkalmazásával az alábbi kódot. Azonban, amikor megérinti egy elemet (és a kiemelő jelenik meg), a kép visszaáll az alapértelmezett piros csap. Hogyan maradhat a egyéni képet, akkor is, ha a kiemelő jelenik meg?

- (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];
}
A kérdést 05/04/2010 00:08
a forrás felhasználó
Más nyelveken...                            


2 válasz

szavazat
5

Azt találták, hogy a pinAnnotation egy MKAnnotationView helyett MKPinAnnotationView, megkaptam a kívánt eredményt. A kép nem kapcsolja be a pin többé

    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"];
Válaszolt 23/11/2010 08:47
a forrás felhasználó

szavazat
0

Be kell használni egy subview helyett a kép tulajdonság. Ez a kód succssfully megoldja a problémát számomra:

    UIImage * image = [UIImage imageNamed:@"blue_pin.png"];
    UIImageView *imageView = [[[UIImageView alloc] initWithImage:image] autorelease];
    [annView addSubview:imageView];
Válaszolt 20/05/2010 12:53
a forrás felhasználó

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