我已经在这个问题上工作了 6 个小时,但我仍在苦苦挣扎。
我有一个地图视图,我正在添加这样的 MKPolygons:
for (MKPolygon *polygon in arrPolygon){
[mapView addOverlay:polygon];
[mapView addAnnotation:polygon];
}
我正在查找哪个多边形覆盖被点击并以编程方式选择相应的注释:
WildcardGestureRecognizer *tapges=[[WildcardGestureRecognizer alloc] init];
tapges.touchesBeganCallback = ^(NSSet * touches, UIEvent * event) {
UITouch *touch = [touches anyObject];
tappedOverlay = nil;
if([touch tapCount]==1){
for (id<MKOverlay> overlay in mapView.overlays)
{
MKOverlayView *view = [mapView viewForOverlay:overlay];
if ([overlay isKindOfClass:[MKPolygon class]] && view)
{
// Get view frame rect in the mapView's coordinate system
CGRect viewFrameInMapView = [view.superview convertRect:view.frame toView:mapView];
// Get touch point in the mapView's coordinate system
CGPoint point = [touch locationInView:mapView];
// Check if touch is within the view
if (CGRectContainsPoint(viewFrameInMapView, point))
{
tappedOverlay = overlay;
[mapView selectAnnotation:tappedOverlay animated:NO];
break;
}
}
}
}
};
当我这样做时,为同一个 MKAnnotationView 对象调用了 didSelectAnnotationView 和 didDeselectAnnotationView。我的问题是,为什么要调用 Deselect 方法?
当我手动选择 Annotation 时,它不会调用 Deselect 方法,这意味着它可以正常工作。
谢谢你 !!!