Automatic "canShowCallOut" anotace IPHONE

hlasů
4

V Wich způsobem bych mohl zavolat funkci, která automaticky otevře svůj anotaci (s titulem, titulky, atd), spíše než na dotek na anotaci na MapView?

Položena 20/03/2010 v 17:36
zdroj uživatelem
V jiných jazycích...                            


2 odpovědí

hlasů
4

Implementovat MKMapViewDelegatedelegáta;

implementovat - (MKAnnotationView *) mapView: (MKMapView *) mapView_ viewForAnnotation: (id <MKAnnotation>) annotation_;; například takto:

    - (MKAnnotationView *) mapView: (MKMapView *) mapView_ viewForAnnotation: (id <MKAnnotation>) annotation_ {

    MKPinAnnotationView *pin = (MKPinAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier: @"YourPinId"];
    if (pin == nil) {
        pin = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation_ reuseIdentifier: @"YourPinId"] autorelease];
    }
    else {
        pin.annotation = annotation_;
    }
    pin.pinColor = MKPinAnnotationColorRed;
    [pin setCanShowCallout:YES];
    pin.animatesDrop = YES;
    return pin;
}

Zobrazit kolík po mapě dokončení načítání:

- (void) dropPin {
    [mapView addAnnotation:self.annotation];
    [mapView selectAnnotation:self.annotation animated:YES];        
}

- (void) mapViewDidFinishLoadingMap: (MKMapView *) mapView_ {
    // if done loading, show the call out
    [self performSelector:@selector(dropPin) withObject:nil afterDelay:0.3];
}

Tento kód má vlastnost volal anotace, který implementuje MKAnnotation. Také, to oživuje spadnout špendlík taky, ale to by mělo být docela samo-vysvětlující.

HTH.

Odpovězeno 21/03/2010 v 21:47
zdroj uživatelem

hlasů
3

Alfons odpověděl na otázku, ale pokud hledáte pro co přesně se automaticky otevře popisek, je tato část:

[mapView selectAnnotation:annotation animated:YES]; 
Odpovězeno 10/01/2012 v 05:09
zdroj uživatelem

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