在我的iphone应用程序中,我使用MapKit和MKMapView以及自定义的MKAnnotationView。在地图上重叠注释(MKAnnotationView)的问题
问题是当地图上的注释重叠时(在我的应用中,注释是照片并且这些照片可能重叠),并且当您点击前面出现的注释时,它是接收事件的另一个注释(背面)似乎是随机的)。
我没有找到任何方法将事件发送到前面的注释。 我不敢相信这个bug /问题没有任何解决方案!
Z ordering和Order of overlapping annotations关于stackoverflow的问题并没有多大帮助。
欢迎任何想法(甚至肮脏的解决方案)!
下面是一些我的代码(没有什么花哨,很常见的):
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
主要类 ... //注解加入,其中一些重叠与他人。
- (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;
}
好主意。我做了透明UIView,发现它缺乏。 – 2010-04-24 18:01:16
我很想知道你是如何处理第三点的。你如何找到某个CGPoint或CGRect的最前面的注释? – samvermette 2010-10-21 17:18:52