28

MKMapView と MKAnnotationView を使用しています。

地図に注釈があります。ユーザーがそれをタップすると、callOut バブルが表示されます。注釈が再びタップされたとき (および callOut バブルが表示されているとき)、別のビューに変更する必要があります。

2 回目のタップ、またはバブル内のタップを検出するにはどうすればよいですか?

4

7 に答える 7

12

を初期化するときにジェスチャ認識機能を追加できますMKAnnotationViewか?

内部のコードはこちらdequeueReusableAnnotationViewWithIdentifier:

UITapGestureRecognizer *tapGesture = 
        [[UITapGestureRecognizer alloc] initWithTarget:self 
                                        action:@selector(calloutTapped:)];
[theAnnotationView addGestureRecognizer:tapGesture];
[tapGesture release];

ジェスチャ認識エンジンのメソッド:

-(void) calloutTapped:(id) sender { 
    // code to  display whatever is required next.

    // To get the annotation associated with the callout that caused this event:
    // id<MKAnnotation> annotation = ((MKAnnotationView*)sender.view).annotation;
}
于 2011-10-13T12:39:32.320 に答える
6

ユーザーが Annotation ビューをクリックした後に吹き出しボタンをタップするには、didSelectAnnotationView に UITapGestureRecognizer を追加します。このようにして、アクセサリ ビューを必要とせずに吹き出しにタップを実装できます。

その後、さらなるアクションのために、送信者から注釈オブジェクトを取得できます。

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self  action:@selector(calloutTapped:)];
    [view addGestureRecognizer:tapGesture];
}

-(void)calloutTapped:(UITapGestureRecognizer *) sender
{
    NSLog(@"Callout was tapped");

    MKAnnotationView *view = (MKAnnotationView*)sender.view;
    id <MKAnnotation> annotation = [view annotation];
    if ([annotation isKindOfClass:[MKPointAnnotation class]])
    {
        [self performSegueWithIdentifier:@"annotationDetailSegue" sender:annotation];
    }
}
于 2014-11-06T01:23:55.410 に答える