gpt4 book ai didi

ios - 无法将 MKPolylineView 带到前面

转载 作者:行者123 更新时间:2023-11-29 12:47:29 29 4
gpt4 key购买 nike

我有一个 MKMapView,其中有一些路线有时会在它们之间重叠,我想在 View 前面显示一个特定的路线。我正在尝试这个,但似乎没有用:

[[polylineViewZoom superview] bringSubviewToFront:polylineViewZoom];

polylineViewZoom is a MKPolylineView.

提前致谢!

最佳答案

而不是访问 MKPolylineViewsuperview直接使用 insertOverlay:atIndex: MKMapView提供的方法类。

insertOverlay:atIndex:方法重新定位 View /显示层次结构中已经被添加到 map (使用 addOverlayaddOverlays )的叠加层。所谓“重新定位”,我并不是说覆盖层的坐标发生变化——只是 z-index 控制它与其他覆盖层的重叠。

您通过了 id<MKOverlay>反对此方法(不是 MKOverlayViewMKOverlayRenderer )。 map View 在内部负责根据需要操作 View 或图层。

此方法适用于 iOS 6 和 iOS 7。

对于 index参数,值为 0 表示 View 层次结构的“底部”和最高层的叠加层 index将在“顶部”或“前面”。

因此,如果您向 map 添加了 5 个叠加层,则 index范围是从 0 到 4 并设置叠加层的 index到 4 会将它带到前面。

例子:

//Somewhere earlier, you add the overlay to the map view using
//addOverlay or addOverlays.

//...

//Later, when you want to bring an overlay to the front, get a reference
//to the overlay either from the map view's overlays array
//or you might keep a reference to it in an instance variable.
id<MKOverlay> someOverlay = ...;

//calculate index for the last ("top") overlay...
NSUInteger maxIndex = self.mapView.overlays.count - 1;

[self.mapView insertOverlay:someOverlay atIndex:maxIndex];

请注意,还有一些其他方法与更改覆盖层次结构相关,您可能会发现它们很有用(例如 exchangeOverlay:withOverlay:insertOverlay:aboveOverlay: 等)。查看 MKMapView有关详细信息的类引用。

关于ios - 无法将 MKPolylineView 带到前面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23293179/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com