MKPinAnnotationView 上的双选触摸
编辑:将标题从“双击..”更改为“双击选择触摸..”
我需要在我的应用程序中检测至少对 MKPinAnnotationView 的第二次触摸。目前我能够进行第一次接触(我从这里使用 kvo:检测何时在 MKMapView 中选择 MKAnnotation),并且它与第一次触摸),但如果我再次点击引脚,则不会调用任何内容,因为所选值不会更改。我尝试使用自 ios 4 以来有效的“mapView:didSelectAnnotationView:”进行相同的操作,但在第二次点击时也不会再次调用。
如果有人能帮助我解决这个问题,那就太好了!
最好的祝福
编辑,添加更多信息:
所以,触摸不必很快,如果用户触摸引脚,我会在注释的标题和副标题中显示一条消息,如果用户再次触摸相同的引脚,所以我会用它做另一件事
Edit: changed the title from : "Double tap .." to "Double selection touch.."
I need to detect at least a second touch over a MKPinAnnotationView in my app. Currently I`m able to get the first touch (I'm using kvo from here: Detecting when MKAnnotation is selected in MKMapView), and it works great with the first touch), but if i tap again on the pin, nothing is called, because the selected value doesn't change. I tried the same using "mapView:didSelectAnnotationView:" that works since ios 4, but it also doesn't get called again on the second tap.
If somebody can helps me with this, it would be great!
Best Regards
Edit, add more info:
So, the touches doesn't have to be quick, if the user touches the pin, ill show a message in the title and subtitle of the annotation, if the user touch again the same pin, so I`ll do another thing with that
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建一个
UITapGestureRecognizer
并将numberOfTapsRequired
设置为2
。将此手势识别器添加到您的MKPinAnnotationView
实例中。此外,您需要将控制器设置为手势识别器的委托并实现-gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
并返回YES
以防止您的手势识别器踩踏这些手势由MKMapView
内部使用。编辑:抱歉我误解了。您所描述的内容应该可以使用
-mapView:didSelectAnnotationView:
和配置为仅需要 1 次点击的手势识别器来实现。我们的想法是,我们只会在选择注释视图时将手势识别器添加到注释视图中。当取消选择注释视图时,我们将删除它。这样您就可以在-tapGestureRecognized:
方法中处理缩放,并且保证仅在注释已被点击时才执行。为此,我将添加手势识别器作为类的属性,并在
-viewDidLoad
中配置它。假设它被声明为@property (nonatomic, Strong) UITapGestureRecognizer *tapGesture;
并且我们正在使用 ARC。Create a
UITapGestureRecognizer
and setnumberOfTapsRequired
to2
. Add this gesture recognizer to your instance ofMKPinAnnotationView
. Additionally, you will need to set your controller as the delegate of the gesture recognizer and implement-gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
and returnYES
to prevent your gesture recognizer from stomping on the ones used internally byMKMapView
.Edit: Sorry I misunderstood. What you're describing should be possible using
-mapView:didSelectAnnotationView:
and the gesture recognizer configured for only 1 required tap. The idea is that we're only going to add the gesture recognizer to an annotation view when it is selected. We'll remove it when the annotation view is deselected. This way you can handle the zooming in the-tapGestureRecognized:
method and it's guaranteed to only be executed if the annotation was already tapped.For this I would add the gesture recognizer as a property of your class and configure it in
-viewDidLoad
. Assume it is declared as@property (nonatomic, strong) UITapGestureRecognizer *tapGesture;
and that we're using ARC.