Trong ứng dụng iphone của tôi, tôi đang sử dụng MapKit với MKMapView và MKAnnotationView tùy chỉnh.Vấn đề với chú thích chồng chéo (MKAnnotationView) trên bản đồ
Vấn đề là khi chú thích chồng chéo trên bản đồ (trong ứng dụng của tôi, chú thích là ảnh và ảnh đó có thể trùng lặp) và khi bạn nhấn vào chú thích xuất hiện ở phía trước, đó là chú thích khác (mặt sau) nhận sự kiện (dường như là ngẫu nhiên).
Tôi không tìm thấy bất kỳ cách nào để gửi sự kiện tới chú thích trước. Tôi không thể tin rằng lỗi/vấn đề này không có giải pháp nào!
Z ordering và Order of overlapping annotations câu hỏi về lưu lượng truy cập không giúp ích nhiều cho tôi.
Vui lòng bất kỳ ý tưởng nào được hoan nghênh (ngay cả các giải pháp bẩn)!
Dưới đây là một số mã của tôi (không có gì lạ mắt, rất phổ biế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
lớp Main ... // Chú thích được thêm vào và một số trong số họ chồng chéo với những người khác.
- (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;
}
Ý tưởng tuyệt vời. Tôi đã làm UIView minh bạch và thấy nó thiếu. –
Tôi rất muốn biết bạn đang đối phó với điểm đạn thứ ba như thế nào. Làm thế nào để bạn tìm thấy chú thích phía trước tại một CGPoint hoặc CGRect nhất định? – samvermette