2011-03-19 93 views
2

如何为MKMapView创建触摸事件。 我正在使用UIViewController并在使用接口生成器时添加MKMapView。 现在我需要处理该地图的触摸事件.....如何为MKMapView创建触摸事件?

我试着写UITouch委托方法 但我失败了......它没有被调用。

请张贴的解决方案如何处理上的MKMapView触摸事件.....

在此先感谢...

回答

6

如果你很高兴使用iOS 4以上的解决方案,我用UIGesture识别器并从未遇到过问题。

这里的长期压力手势的例子(点住):

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

然后你就可以处理,即使在您的handleLongPressGesture:方法:

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

感谢罗格,它的工作 – 2011-03-19 09:14:03