2011-09-22 21 views
6

私はViewControllerにMKMapViewを持っていて、ユーザーがこれらの方法で地図に触れるときにジェスチャーを検出したいと思っています:iOS 5のMKMapViewでユーザーの接触を検出する

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; 
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event; 
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event; 
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event; 

アプリはiOS 3、iOS 4 でもうまく動作しますが、 iOS 5でiPhoneを実行しているアプリでは、次のメッセージが表示されます。

Pre-iOS 5.0 touch delivery method forwarding relied upon. Forwarding -touchesCancelled:withEvent: to <MKAnnotationContainerView: 0x634790; frame = (0 0; 262144 262144); autoresizesSubviews = NO; layer = <CALayer: 0x634710>> 

と上記の4つの方法のコードには達しません。

あなたはそれを修正する方法を知っていますか?

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

+1

まだiOS 5ではコメントできませんが、3.2から4の場合は、touchesメソッドの代わりにUIGestureRecognizerを使用する方が簡単です。 – Anna

+0

http://stackoverflow.com/questions/1049889/how-to-intercept-touches-events-on-a-mkmapview-or-uiwebview-objects ..このリンクをチェックする – Kalpesh

答えて

1

UIGestureRecognizerのフォームはあなたを助けることができます。マップビューで使用されているタップレコグナイザの例を次に示します。これがあなたが探しているものでないかどうか私に知らせてください。

// in viewDidLoad... 

// Create map view 
MKMapView *mapView = [[MKMapView alloc] initWithFrame:(CGRect){ CGPointZero, 200.f, 200.f }]; 
[self.view addSubview:mapView]; 
_mapView = mapView; 

// Add tap recognizer, connect it to the view controller 
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(mapViewTapped:)]; 
[mapView addGestureRecognizer:tapRecognizer]; 

// ... 

// Handle touch event 
- (void)mapViewTapped:(UITapGestureRecognizer *)recognizer 
{ 
    CGPoint pointTappedInMapView = [recognizer locationInView:_mapView]; 
    CLLocationCoordinate2D geoCoordinatesTapped = [_mapView convertPoint:pointTappedInMapView toCoordinateFromView:_mapView]; 

    switch (recognizer.state) { 
     case UIGestureRecognizerStateBegan: 
      /* equivalent to touchesBegan:withEvent: */ 
      break; 

     case UIGestureRecognizerStateChanged: 
      /* equivalent to touchesMoved:withEvent: */ 
      break; 

     case UIGestureRecognizerStateEnded: 
      /* equivalent to touchesEnded:withEvent: */ 
      break; 

     case UIGestureRecognizerStateCancelled: 
      /* equivalent to touchesCancelled:withEvent: */ 
      break; 

     default: 
      break; 
    } 
} 
関連する問題