3

次のようUITapGestureRecognizerに、 を に追加しました。MKMapView

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]
                                      initWithTarget:self 
                                      action:@selector(doStuff:)];
[tapGesture setCancelsTouchesInView:NO]; 
[tapGesture setDelaysTouchesEnded:NO]; 
[[self myMap] addGestureRecognizer:tapGesture];
[tapGesture release];

これはほとんど機能します。タップ ジェスチャは認識され、ダブルタップでもマップがズームされます。残念ながら、 は、タップ ジェスチャによってもトリガーされる要素UITapGestureRecognizerの選択と選択解除を妨げます。MKAnnotationView

setCancelsTouchesInViewプロパティとプロパティを設定しsetDelaysTouchesEndedても効果はありません。を追加しないと、注釈の選択は正常に機能しUIGestureRecognizerます。

私は何が欠けていますか?

アップデート:

以下のAnna Kareninaが示唆しているように、この問題YESshouldRecognizeSimultaneouslyWithGestureRecognizer:delegateメソッドに戻ることで回避できます。

この回答の詳細。

4

1 に答える 1

0

タップジェスチャの代わりに、以下のように長押しジェスチャを追加します:-

UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc] 
        initWithTarget:self action:@selector(longpressToGetLocation:)];
    lpgr.minimumPressDuration = 2.0;  //user must press for 2 seconds
    [mapView addGestureRecognizer:lpgr];
    [lpgr release];


- (void)longpressToGetLocation:(UIGestureRecognizer *)gestureRecognizer
{
    if (gestureRecognizer.state != UIGestureRecognizerStateBegan)
        return;

    CGPoint touchPoint = [gestureRecognizer locationInView:self.mapView];   
    CLLocationCoordinate2D location = 
        [self.mapView convertPoint:touchPoint toCoordinateFromView:self.mapView];

    NSLog(@"Location found from Map: %f %f",location.latitude,location.longitude);

}
于 2013-02-12T09:16:45.093 に答える