2011-09-22 17 views
6

Bir viewController bir MKMapView varsa ve o/o bu yöntemlerle haritayı dokunduğunda kullanıcıların hareketleri algılamak istiyorum:iOS'taki MKMapView kullanıcı dokunuşları Algılama 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; 

uygulaması iOS ile çalışıyor

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

ve yukarıdaki 4 yöntemlerde kodu ulaşmış değildir: iPhone iOS 5 üzerinde çalışan uygulamayı hata ayıklama 3, iOS 4 ama, ben bu mesajı görebilirsiniz.

Nasıl düzeltebileceğinizi biliyor musunuz?

Teşekkürler.

+1

Henüz iOS 5 üzerinde yorum yapamıyorum, ancak 3.2 ila 4 için, dokunma yöntemleri yerine bir UIGestureRecognizer kullanmak daha kolay olabilir. – Anna

+0

http://stackoverflow.com/questions/1049889/how-to-intercept-touches-events-on-a-mkmapview-or-uiwebview-objects .. Bu Bağlantıyı Kontrol Edin – Kalpesh

cevap

1

Bazı formlar UIGestureRecognizer size yardımcı olabilir. İşte harita görünümünde kullanılan bir musluk tanıyıcı örneği; Aradığın şey bu değilse bana haber ver.

// 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; 
    } 
} 
İlgili konular