点击叠加时显示标注 [英] Show callout when tapping overlay

查看:145
本文介绍了点击叠加时显示标注的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有多个叠加层的MKMapView。工作一切都很好,它的工作简单,令人难以置信。然而,有一件事我无法开展工作。这个想法很简单:当用户点击覆盖覆盖的区域时,必须出现带有关于该覆盖的一些信息的标注。叠加层都是 MKPolygon s,它遵循MKOverlay协议,因此遵循MKAnnotation协议。

I have an MKMapView with several overlays. Works all just fine, and it's incredible how simple it works. There is, however, one thing I can't get to work. The idea is simple: when a user taps within the area that is covered by an overlay, a callout with some information about that overlay has to come up. The overlays are all MKPolygons, which follow the MKOverlay protocol and therefore the MKAnnotation protocol.


MKOverlay协议符合
MKAnnotation协议。因此,
所有重叠对象也是
注释对象,并且可以将
视为代码中的一个或两个。
如果您选择将叠加对象
视为两者,则您需要在两个位置管理该对象的
。如果
你想要显示覆盖
视图和注释视图,你
必须实现
mapView:viewForOverlay:和
mapView:viewForAnnotation:方法在
你的申请代表。它也是
意味着你必须从你的地图的叠加和
注释数组中添加和删除
对象。

The MKOverlay protocol conforms to the MKAnnotation protocol. As a result, all overlay objects are also annotation objects and can be treated as one or both in your code. If you opt to treat an overlay object as both, you are responsible for managing that object in two places. If you want to display both an overlay view and annotation view for it, you must implement both the mapView:viewForOverlay: and mapView:viewForAnnotation: methods in your application delegate. It also means that you must add and remove the object from both the overlays and annotations arrays of your map.

这来自Apple文档。我试过这样的事情:

This comes from the Apple docs. I tried something like this:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {

      MKAnnotationView *aView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil];
      aView.canShowCallout = YES;
}

但这似乎不起作用。我尝试过使用手势识别器,但我不知道除了使用 canShowCallOut 属性之外如何显示标注...

But that doesn't seem to work. I've tried using gesture recognizers, but I have no idea how to show a callout other than by using the canShowCallOut property...

推荐答案

我想你必须添加MKOverlays作为注释

I suppose you have to add the MKOverlays as annotations also

 [self.mapView addAnnotations:myOverlays];

然后返回一个未隐藏的(mapView:viewForAnnotation)中的MKAnnotationView,或者是图形(可点击) )或零阿尔法视图。接下来,为每个MKOverlayView添加一个UITapGestureRecognizer,确保它适用于地图的手势(用于同时识别的UIGestureRecognizerDelegate实现)。最后,当您的手势识别器触发时,执行此操作

Then return a MKAnnotationView in (mapView:viewForAnnotation) that's not hidden, either a graphic (tap-able) or zero alpha view. Next, add a UITapGestureRecognizer for each MKOverlayView, make sure it works with the map's gestures (UIGestureRecognizerDelegate implementation for simultaneous recognition). Finally when your gesture recognizer fires do this

[self.mapView setSelectedAnnotations:[NSArray arrayWithObject:myOverlayView.overlay]];

我不确定这实际上会触发callOut显示。
还要确保您的叠加对象的返回标题和/或副标题。

I'm not certain that this actually triggers the callOut showing though. Also make sure your return title and/or subtitle from your overlay object.

这篇关于点击叠加时显示标注的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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