一つの方法は、UIGestureRecognizerDelegate
方法gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
を実装し、その中にYES
を返すことです:
//add <UIGestureRecognizerDelegate> to .h to avoid compiler warning
//add this where you create tapGestureRecognizer...
tapGestureRecognizer.delegate = self;
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
今、あなたのmapViewTapped:
が呼び出されます、その後、マップビューの認識装置は、そのメソッドを呼び出します。タップがアノテーションビューにあった場合、マップビューにコールアウトが表示されます(実装した場合はdidSelectAnnotationView
デリゲートメソッドが呼び出されます)。
その後、
別の方法として、あなたはより多くの制御が必要な場合は、代わりに上記をやって、あなたのmapViewTapped:
であなたは、その吹き出しが表示されます注釈を選択し、手動でその後、タップは注釈ビューにあったかどうかを確認することができ(と)didSelectAnnotationView
デリゲートメソッドを呼び出します。
-(void)mapViewTapped:(UITapGestureRecognizer *)tgr
{
CGPoint p = [tgr locationInView:mapView];
UIView *v = [mapView hitTest:p withEvent:nil];
id<MKAnnotation> ann = nil;
if ([v isKindOfClass:[MKAnnotationView class]])
{
//annotation view was tapped, select it...
ann = ((MKAnnotationView *)v).annotation;
[mapView selectAnnotation:ann animated:YES];
}
else
{
//annotation view was not tapped, deselect if some ann is selected...
if (mapView.selectedAnnotations.count != 0)
{
ann = [mapView.selectedAnnotations objectAtIndex:0];
[mapView deselectAnnotation:ann animated:YES];
}
}
}
は、あなたの説明だけ有用ではありませんでした、ありがとうございますが、非常に詳細な – MegaManX
多くのおかげで、2つ目の提案は、私が後だったまさにでした! – MrDB
素晴らしい提案、私が探していたものでした –