De quelle façon puis-je appeler la fonction qui ouvre automatiquement mon annotation (avec titre, sous-titre, etc.), plutôt que de toucher à l'annotation sur la carte?Annotation automatique "canShowCallOut" IPHONE
Répondre
Outil MKMapViewDelegate
délégué;
Outil - (MKAnnotationView *) mapView: (MKMapView *) mapView_ viewForAnnotation: (id <MKAnnotation>) annotation_;
; par exemple comme ceci:
- (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;
}
Afficher la broche après la carte a terminé le chargement:
- (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];
}
Ce code a une propriété appelée annotation qui implémente MKAnnotation
. En outre, il anime la chute de broche aussi, mais il devrait être assez explicite.
HTH.
Alfons répondu à la question, mais si vous cherchez quoi exactement ouvre automatiquement la légende, il est cette partie:
[mapView selectAnnotation:annotation animated:YES];
Brillant! Une solution simple, mais exactement ce que je cherchais. Une ligne de code (après avoir créé une nouvelle annotation) pour obtenir l'affichage du titre et du sous-titre. Merci pour ce conseil –
Merci beaucoup ... très utile! – Mat