iPhone:在MKMapView中检测Tap

Chr*_*sJF 22 cocoa-touch mapkit mkmapview ios

如何在实例上检测到单击MKMapView?我是否必须继承MKMapView并重写该touchesEnded方法?

谢谢,

-克里斯

pse*_*ach 33

如果您只是希望在不影响地图的任何其他触摸行为的情况下获得点击手势的通知,那么您将需要使用UITapGestureRecognizer.它非常简单,只需输入一些像这样的代码.

UITapGestureRecognizer* tapRec = [[UITapGestureRecognizer alloc] 
   initWithTarget:self action:@selector(didTapMap:)];
[theMKMapView addGestureRecognizer:tapRec];
[tapRec release];
Run Code Online (Sandbox Code Playgroud)

这将调用didTapMap每当theMKMapView接收到轻击手势并且所有捏合和拖动手势仍将像以前一样工作.