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?
Automatic "canShowCallOut" anotace IPHONE
hlasů
4
2 odpovědí
hlasů 4
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.
hlasů 3
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];













