How to create touch events for MKMapView?

How to create Touch Events for MKMapView. I'm using UIViewController and adding MKMapView on that using interface builder. Now I need to handle touch events for that map.....

I tried by writing UITouch Delegate methods But I failed...It is not getting called.

Please post a solution how to handle touch events on MKMapView.....

Thanks in advance...

Upvotes: 2

Views: 1967

Answers (1)

Rog
Rog

Reputation: 18670

If you are happy with an iOS 4 and above solution, I've used UIGesture recognisers and never had a problem.

Here's an example for a long pressure gesture (tap and hold):

// Long press gesture recogniser
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc]
                                                  initWithTarget:self 
                                                          action:@selector(handleLongPressGesture:)];
[self.view addGestureRecognizer:longPressGesture];
[longPressGesture release];

And then you can handle the even in your handleLongPressGesture: method:

-(void)handleLongPressGesture:(UILongPressGestureRecognizer*)sender 
{
     if (sender.state == UIGestureRecognizerStateEnded || sender.state == UIGestureRecognizerStateChanged)
          return;
     else {
         // Your app logic here...
     }
}

Upvotes: 6

Related Questions