User touch detection on MKMapView in iOS 5

I have MKMapView in the ViewController and you want to detect user gestures when it touches the map using these methods:

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

The application works fine with iOS 3, iOS 4, but when I debug an application with an iPhone running iOS 5, I see this message:

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

and the code from the above 4 methods is not achieved.

Do you know how to fix this?

Thanks.

+6
source share
1 answer

Some form of UIGestureRecognizer may help you. Here is an example of a tap recognition device used in a map view; let me know if this is not what you are looking for.

 // 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; } } 
+1
source

Source: https://habr.com/ru/post/897866/


All Articles