可以使用 MapKit 在地图上添加叠加层吗?
是否可以在我的应用程序中添加的地图上添加叠加图像?我正在使用 MapKit 来显示某个区域的地图。我想在引脚显示之前在地图顶部添加覆盖图像
,即堆栈应该是地图->图像覆盖->引脚
是否可以不进入视图层次结构- 获取视图的所有子视图,然后在地图顶部添加图像?
谢谢。
Is it possible to add an overlay image on top of a map added in my app? I am using MapKit to show the map of an area. I would like to add an overlay image on top of the map before the pins show up
i.e. the stack should be map->image overlay->pins
Is it possible without going into the hierarchy of views - get all subviews of the view and then add an image just on top of the map?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我知道您需要一种静态地图的解决方案,但这里有一个“可拖动”地图的解决方案,它也应该可以解决您的问题。
您应该子类
MKOverlayView
,并覆盖它(默认为空):- (void)drawMapRect:(MKMapRect)mapRect ZoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context
。该方法实际上应该执行
drawRect
在视图中执行的操作。您还应该实现另一个“应该”方法,如果覆盖层应该在屏幕上可见(在您的情况下......总是?),则该方法应该返回 TRUE。
在重写方法中,您应该在地图顶部绘制图像(当然根据mapRect和zoomScale),并且中提琴!
更多参考:
http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/LocationAwarenessPG/AnnotatingMaps/AnnotatingMaps.html#//apple_ref/doc/uid/TP40009497-CH6-SW15
I know that you need a solution for a static map , but here's one for a "draggable" one , which should also solve your problem.
You should subclass
MKOverlayView
, and override its (empty by default):- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context
.The method should actually do what
drawRect
does in views.You should also implement another "should" method , that should return TRUE if the overlay should be visible on screen (in your case.. always ?).
In the overriden method , you should draw your image on top of the map (according to the mapRect and zoomScale of course) , and viola!
Some more reference :
http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/LocationAwarenessPG/AnnotatingMaps/AnnotatingMaps.html#//apple_ref/doc/uid/TP40009497-CH6-SW15
尝试查看
MKMapView
文档中概述的MKOverlayView
(请参阅 链接)。此外,可能值得回顾一下“Apple WWDC Session 127 - Customizing Maps with Overlays”。Try taking a look into the
MKOverlayView
outlined in theMKMapView
documentation (see link). In addition, it may be worth reviewing "Apple WWDC Session 127 - Customizing Maps with Overlays".如果您观看“Apple WWDC Session 127 - 使用叠加层自定义地图”会议,其中有一部分是关于光栅图像作为叠加层的。如果您下载 2010 WWDC 示例代码,其中有一个名为“TileMap”的示例,其中包含执行此操作的代码。
If you watch that "Apple WWDC Session 127 - Customizing Maps with Overlays" session there is a part about about raster images as overlays. If you download the 2010 WWDC Sample Code there is an example named "TileMap" which has the code for doing that.