2011-09-22 14 views
6

Tengo un MKMapView en un ViewController y me gustaría para detectar los gestos de los usuarios cuando él/ella toca el mapa con estos métodos:detectar toques de usuario en MKMapView en IOS 5

- (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; 

La aplicación funciona bien con iOS 3, el iOS 4 pero cuando puedo depurar la aplicación con el iPhone se ejecuta en iOS 5, veo este mensaje:

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>> 

y el código en los 4 métodos anteriores no se alcanzan.

¿Sabes cómo solucionarlo?

Gracias.

+1

Aún no puedo comentar en iOS 5 pero para 3.2 a 4, puede ser más fácil usar un UIGestureRecognizer en lugar de los métodos de toques. – Anna

+0

http://stackoverflow.com/questions/1049889/how-to-intercept-touches-events-on-a-mkmapview-or-uiwebview-objects .. Ver este enlace – Kalpesh

Respuesta

1

Alguna forma de UIGestureRecognizer puede ayudarlo. Aquí hay un ejemplo de un reconocedor de tap que se usa en una vista de mapa; avísame si esto no es lo que estás buscando.

// 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; 
    } 
} 
Cuestiones relacionadas