蓝色位置点是可选择的,错误地拦截来自我的MKAnnotationViews的触摸

我的iOS应用程序中有一个普通的地图,其中“显示用户位置”已启用 – 这意味着我在地图上有我的正常蓝点,显示我的位置和准确度信息。 标注在代码中被禁用。

但我也有定制的MKAnnotationViews,它们在地图周围绘制,所有这些都有自定义标注。

这工作正常,但问题是当我的位置在MKAnnotationView的位置时,蓝点(MKUserLocation)拦截触摸,因此MKAnnotationView不会被触及。

如何禁用蓝点上的用户交互,以便MKAnnotationViews而不是蓝点拦截触摸?

这就是我到目前为止所做的事情:

- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id )annotation; { if (annotation == self.mapView.userLocation) { [self.mapView viewForAnnotation:annotation].canShowCallout = NO; return [self.mapView viewForAnnotation:annotation]; } else { ... } } 

禁用标注不会禁用视图上的触摸(仍会调用didSelectAnnotationView )。

要禁用注释视图上的用户交互,请将其enabled属性设置为NO

但是,我NOviewForAnnotation委托方法中将enabled设置为NO ,而是建议在didAddAnnotationViews委托方法中进行,而在viewForAnnotation ,只需为MKUserLocation返回nil

例:

 - (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id )annotation; { if ([annotation isKindOfClass:[MKUserLocation class]]) { return nil; } //create annotation view for your annotation here... } -(void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views { MKAnnotationView *av = [mapView viewForAnnotation:mapView.userLocation]; av.enabled = NO; //disable touch on user location }