En mi aplicación para el iPhone, estoy usando MapKit con MKMapView y costumbre MKAnnotationView.
El problema es cuando las anotaciones se superponen en el mapa (en mi aplicación, las anotaciones son las fotos y las fotos pueden solaparse) y al tocar en la anotación que aparece en la parte frontal, es otra anotación (en la espalda), que recibe el evento (parece ser al azar ).
No he encontrado ninguna manera de enviar el evento a la anotación del delantero. No puedo creer que este error / problema no tiene solución!
Ordenamiento Z y Orden de la superposición de anotaciones preguntas sobre stackoverflow no me ayuda mucho.
Por favor, cualquier idea es bienvenida (incluso soluciones sucias)!
He aquí algunos de mi código (nada especial, muy común):
CustomAnnotation.h
@interface CustomAnnotation : NSObject <MKAnnotation> {
@private
CustomAnnotationView* view;
}
@property (nonatomic, retain) CustomAnnotationView* view;
@end
CustomAnnotation.m
@implementation CustomAnnotation
@synthetize view;
CustomAnnotationView.h
@interface CustomAnnotationView : MKAnnotationView {
}
@end
CustomAnnotationView.m
@implementation CustomAnnotationView
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
// Do something related to the annotation tapped
}
@end
Clase principal ... // se añaden anotaciones y algunos de ellos se solapa con otros.
- (void)addAnnotation:(CustomAnnotation*)annotation {
[map addAnnotation:annotation];
}
...
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
NSString* identifier = getIdentifierFromAnnotation(annotation);
CustomAnnotationView* view;
if(!(view = (CustomAnnotationView*)[map dequeueReusableAnnotationViewWithIdentifier:identifier])) {
view = [[CustomAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier: identifier];
[(CustomAnnotation*)annotation setView:view];
[view release];
}
return view;
}













