如何在MKAnnotations之上显示MKOverlay? [英] How do I show MKOverlay above MKAnnotations?

查看:171
本文介绍了如何在MKAnnotations之上显示MKOverlay?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 MKOverlay (特别是 MKPolyline )来显示地图上的路线。但是,我需要路线显示在我现有的引脚之上(自定义 MKAnnotationView s)。有没有一种方法可以将 MKPolyline 带到引脚上方的正面?

I'm trying to use an MKOverlay (specifically an MKPolyline) to show a route on the map. However, I need the route to show up above my existing pins (custom MKAnnotationViews). Is there a good way to bring the MKPolyline to the front above the pins?

推荐答案

调查注释图层的 zOrder 属性可能很有用。在superview的层次结构中向后发送注释可以帮助您实现所需的效果。更改注释z轴位置应该在 mapView:didAddAnnotationViews:委托方法中完成。

It might be useful to investigate the annotation layer's zOrder property. Sending the annotations backwards in your superview's hierarchy may help you achieve the effect needed. Changing your annotation z-axis position should probably be done within the mapView:didAddAnnotationViews: delegate method.

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
    annotationView.layer.zPosition = x;
}

自从我处理以来已经有一段时间了MKPolyline ,我知道iOS 8中的内容发生了很大的变化,但你可以在绘制时直接操纵折线的z位置。

It's been a while since I've dealt with MKPolyline, and I know things changed a lot in iOS 8, but you might be able to directly manipulate the polyline's z position while you're drawing it.

更新

当您将 MKOverlay 添加到地图,从iOS 7.0+开始,使用 addOverlay:level:方法。这允许您指定叠加层的z位置。由 MKOverlayLevels 定义的叠加层的最高z位置之一是 MKOverlayLevelAboveLabels

UPDATE
When you add your MKOverlay to the map, starting in iOS 7.0+, use the addOverlay:level: method. This allows you to specify the z-position of the overlay. One of the highest z-positions for the overlay as defined by MKOverlayLevels is MKOverlayLevelAboveLabels:


将叠加层放置在地图标签,盾牌或兴趣点图标上方,但低于注释和建筑物的3D投影。

Place the overlay above map labels, shields, or point-of-interest icons but below annotations and 3D projections of buildings.

不幸的是,正如上面的文档中所提到的,地图不支持在注释上方放置叠加层。一种可能的解决方案可能是将注释添加到单独的 MKOverlay 对象,然后使用 insertOverlay将其他覆盖(使用路径)添加到地图:aboveOverlay:

Unfortunately, as mentioned in the documentation above, the map does not support placing overlays above annotations. A possible solution may be to add the annotations to a separate MKOverlay object and then to add the other overlay (with the path) to the map using insertOverlay:aboveOverlay:.

这篇关于如何在MKAnnotations之上显示MKOverlay?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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