点击MKAnnotation时,可防止在MKMapView上检测到触摸事件 [英] Prevent touch events on MKMapView being detected when a MKAnnotation is tapped

查看:103
本文介绍了点击MKAnnotation时,可防止在MKMapView上检测到触摸事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UITapGestureRecognizer,当用户点击Map时会隐藏并显示我的MKMap上的工具栏 - 简单。

I have a UITapGestureRecognizer that will hide and show a toolbar over my MKMap when the user taps the Map - simple.

然而,当用户点击MKMapAnnotation时,我不希望地图以正常方式响应水龙头(上图)。此外,当用户点击地图上的其他位置以取消选择MKAnnotation标注时,我也不希望工具栏响应。因此,工具栏应仅在当前没有MKAnnotations处于选定状态时响应。当用户直接点击注释时,它也不应该响应。

However, when the user taps on an MKMapAnnotation, I do not want the map to respond to a tap in the normal way (above). Additionally, when the user taps elsewhere on the map to de-select an MKAnnotation callout, I also don't want the toolbar to respond. So, the toolbar should only respond when there are no MKAnnotations currently in selected state. Nor should it respond when the user clicks on an annotation directly.

到目前为止,我正在尝试以下对地图上的点击手势作出反应的操作 - 但是永远不会检测到注释视图(第一个if语句),并且无论此方法如何,也会启动注释视图。

So far, I have being trying the following action that reacts to the tap gesture on the map - however the Annotation View is never detected (the first if statement) and also, the annotation view is also launched regardless of this method.

 -(void)mapViewTapped:(UITapGestureRecognizer *)tgr
{
    CGPoint p = [tgr locationInView:self.mapView];

    UIView *v = [self.mapView hitTest:p withEvent:nil];

    id<MKAnnotation> ann = nil;

    if ([v isKindOfClass:[MKAnnotationView class]])<---- THIS CONDITION IS NEVER MET BUT ANNOTATIONS ARE SELECTED ANYWAY
    {
        //annotation view was tapped, select it…
        ann = ((AircraftAnnotationView *)v).annotation;
        [self.mapView selectAnnotation:ann animated:YES];
    }
    else
    {

        //annotation view was not tapped, deselect if some ann is selected...
        if (self.mapView.selectedAnnotations.count != 0)
        {
            ann = [self.mapView.selectedAnnotations objectAtIndex:0];
            [self.mapView deselectAnnotation:ann animated:YES];
        }

        // If no annotation view is selected currently then assume control of
        // the navigation bar.
        else{

            [self showToolBar:self.navigationController.toolbar.hidden];
        }
    }
}

我需要控制发布注释以编程方式调出并检测点击事件何时达到注释以实现此目的。

I need to control the launch of the annotation call out programmatically and detect when the tap event has hit an annotation in order to achieve this.

任何帮助都将受到赞赏。

Any help would be appreciated.

推荐答案

我认为您会发现以下链接非常有用:

I think you will find the following links very useful:

http://blog.asynchrony.com/2010/09/building -custom-map-annotation-callouts-part-2 /

如何使MKAnnotationView触摸敏感?

第一个链接讨论(其中)其他事情)如何防止触摸传播到注释,以便它们选择性地响应,第二个如何检测触摸。

The first link discusses (among other things) how to prevent the propagation of touches to the annotations so that they selectively respond, and the second one how to detect the touches.

这篇关于点击MKAnnotation时,可防止在MKMapView上检测到触摸事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆