如何从MKAnnotationView显示多个标注?

时间:2021-07-21 05:15:23

I like implement sth. like this. I have two annotations with callouts, but MKMapView allows only one to be selected at the same time.

我喜欢实施......喜欢这个。我有两个带标注的注释,但MKMapView只允许同时选择一个。

[mapView selectAnnotation:self.firstAnnotation animated:FALSE];
[mapView selectAnnotation:self.secondAnnotation animated:FALSE];

When I select another annotation, the first one deselected automatically.

当我选择另一个注释时,第一个注释会自动取消选择。

But in the picture below, it's successfully implemented. So how can this be done? http://oi52.tinypic.com/14t3t09.jpg

但在下图中,它已成功实施。那怎么办呢? http://oi52.tinypic.com/14t3t09.jpg

1 个解决方案

#1


5  

Also see "Multiple annotation callouts displaying in MKMapView": Multiple annotation callouts displaying in MKMapView

另请参阅“在MKMapView中显示多个注释标注”:在MKMapView中显示多个注释标注

It appears that the framework does not support multiple selections, so you will have to implement custom callouts for this behavior. The answer to the linked question suggests making your callout a part of your annotation view so you can manage the selection yourself. Personally I like implementing the callout as an separate annotation - I have an example project with custom callouts here:

看起来该框架不支持多个选择,因此您必须为此行为实现自定义标注。链接问题的答案建议将标注作为注释视图的一部分,以便您自己管理选择。我个人喜欢将callout实现为一个单独的注释 - 我在这里有一个带有自定义标注的示例项目:

https://github.com/jacobjennings/JJMapCallout

https://github.com/jacobjennings/JJMapCallout

which was my solution to:

这是我的解决方案:

MKAnnotationView - Lock custom annotation view to pin on location updates

MKAnnotationView - 锁定自定义注释视图以固定位置更新

In this project, I forward the MKMapView delegate methods

在这个项目中,我转发了MKMapView委托方法

- (void)mapView:(MKMapView *)aMapView didSelectAnnotationView:(MKAnnotationView *)aView
- (void)mapView:(MKMapView *)aMapView didDeselectAnnotationView:(MKAnnotationView *)aView

to the respective annotation. This allows me to implement expected callout behaviors. However, you could ignore didDeselectAnnotationView messages to leave callouts visible.

各自的注释。这允许我实现预期的标注行为。但是,您可以忽略didDeselectAnnotationView消息以使标注可见。

To find out if the user taps on the map to clear annotations (didn't tap on a pin), check the value of mapView.selectedAnnotations in your didDeselectAnnotationView method, and if it's empty, you'll know to clear your callouts.

要确定用户是否点击地图以清除注释(未点击引脚),请检查didDeselectAnnotationView方法中mapView.selectedAnnotations的值,如果它为空,您将知道清除标注。

#1


5  

Also see "Multiple annotation callouts displaying in MKMapView": Multiple annotation callouts displaying in MKMapView

另请参阅“在MKMapView中显示多个注释标注”:在MKMapView中显示多个注释标注

It appears that the framework does not support multiple selections, so you will have to implement custom callouts for this behavior. The answer to the linked question suggests making your callout a part of your annotation view so you can manage the selection yourself. Personally I like implementing the callout as an separate annotation - I have an example project with custom callouts here:

看起来该框架不支持多个选择,因此您必须为此行为实现自定义标注。链接问题的答案建议将标注作为注释视图的一部分,以便您自己管理选择。我个人喜欢将callout实现为一个单独的注释 - 我在这里有一个带有自定义标注的示例项目:

https://github.com/jacobjennings/JJMapCallout

https://github.com/jacobjennings/JJMapCallout

which was my solution to:

这是我的解决方案:

MKAnnotationView - Lock custom annotation view to pin on location updates

MKAnnotationView - 锁定自定义注释视图以固定位置更新

In this project, I forward the MKMapView delegate methods

在这个项目中,我转发了MKMapView委托方法

- (void)mapView:(MKMapView *)aMapView didSelectAnnotationView:(MKAnnotationView *)aView
- (void)mapView:(MKMapView *)aMapView didDeselectAnnotationView:(MKAnnotationView *)aView

to the respective annotation. This allows me to implement expected callout behaviors. However, you could ignore didDeselectAnnotationView messages to leave callouts visible.

各自的注释。这允许我实现预期的标注行为。但是,您可以忽略didDeselectAnnotationView消息以使标注可见。

To find out if the user taps on the map to clear annotations (didn't tap on a pin), check the value of mapView.selectedAnnotations in your didDeselectAnnotationView method, and if it's empty, you'll know to clear your callouts.

要确定用户是否点击地图以清除注释(未点击引脚),请检查didDeselectAnnotationView方法中mapView.selectedAnnotations的值,如果它为空,您将知道清除标注。