私はこの問題に 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 メソッドが呼び出されないため、正常に動作します。
ありがとうございました !!!