MKMapView と MKAnnotationView を使用しています。
地図に注釈があります。ユーザーがそれをタップすると、callOut バブルが表示されます。注釈が再びタップされたとき (および callOut バブルが表示されているとき)、別のビューに変更する必要があります。
2 回目のタップ、またはバブル内のタップを検出するにはどうすればよいですか?
MKMapView と MKAnnotationView を使用しています。
地図に注釈があります。ユーザーがそれをタップすると、callOut バブルが表示されます。注釈が再びタップされたとき (および callOut バブルが表示されているとき)、別のビューに変更する必要があります。
2 回目のタップ、またはバブル内のタップを検出するにはどうすればよいですか?
を初期化するときにジェスチャ認識機能を追加できます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;
}
ユーザーが 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];
}
}