2012-06-29 11 views
6

私の仕事は、2番目のタップで地図注釈の選択を解除することです。2番目のタップで地図注釈の選択を解除する方法

私はmapView関数でそれを行う方法が見つかりませんでした。だから私はstackoverflowから記事を使用してこのように:

- (void)viewDidLoad 
{ 
    annotationTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(annotationTapRecognized:)]; 
    annotationTap.numberOfTapsRequired = 1; 
    annotationTap.delegate = self; 
} 

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view 
{ 
    [view addGestureRecognizer:annotationTap]; 
} 

- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view 
{ 
    [view removeGestureRecognizer:annotationTap]; 
} 

- (void)annotationTapRecognized:(UIGestureRecognizer *)gesture 
{ 
    NSArray *selectedAnnotations = self.viewMap.selectedAnnotations; 
    for (MapAnnotation *annotationView in selectedAnnotations) { 
     [self.viewMap deselectAnnotation:annotationView animated:NO]; 
    } 
} 

それは正しく動作するようですが、そうではありません。アノテーションを2回タップすると、コールアウトが消えて再び表示されます。

アイデア?

ありがとうございます。

答えて

18

解決策が見つかりました。多分それは良くありません。

luxsypherが指摘したように、ブール値「is show」を追加しました。だから私の関数は次のようになります:

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view 
{ 
    [view addGestureRecognizer:annotationTap]; 

    if (isShow) { 
     NSArray *selectedAnnotations = self.viewMap.selectedAnnotations; 
     for (MapAnnotation *annotationView in selectedAnnotations) { 
      [self.viewMap deselectAnnotation:annotationView animated:YES]; 
     } 
     isShow = FALSE; 
    } 
} 

- (void)annotationTapRecognized:(UIGestureRecognizer *)gesture 
{ 
    NSArray *selectedAnnotations = self.viewMap.selectedAnnotations; 
    for (MapAnnotation *annotationView in selectedAnnotations) { 
     [self.viewMap deselectAnnotation:annotationView animated:YES]; 
    } 
    isShow = TRUE; 
} 

多分それは誰かにとって役に立ちます:)。

ありがとうございました。

1

おそらくブール値「可視」が追加され、結果的に動作するはずです。ジェスチャーが呼び出された後、「選択しました」が再び呼び出されたように見えます。

+0

しかし、どこに追加しましたか?私はこれについて考えました。しかし、クリックでコールアウトを表示することを禁止するにはどうすればよいですか?ありがとう。 – Igor

関連する問題