如何在MKMapView上禁用用户交互? [英] How to disable user interaction on MKMapView?
问题描述
如何在iOS中禁用与整个地图(MKMapView)的用户交互?我只想禁用缩放,点击等功能,并显示静态地图. [self.mapView setUserInteractionEnabled:NO]
无效.在Stack 上没有找到通过Google或其他答案的有效解决方案(如果找到有效答案,请链接.).以iOS 5为目标.应该有一种更简单的方法.
How do you disable user interaction to an entire Map (MKMapView) in iOS? I just want to disable zooming, tapping, etc and show a static map. [self.mapView setUserInteractionEnabled:NO]
didn't work. Found no working solutions via Google or other answers here on Stack (pls link if you find a working answer..). Targeting iOS 5. There should be an easier way to do this.
推荐答案
关键是禁用缩放和滚动.
The key is to disable zooms and scrolls.
在Objective-C中:
In Objective-C:
self.mapView.zoomEnabled = false;
self.mapView.scrollEnabled = false;
self.mapView.userInteractionEnabled = false;
或者Swift:
mapView.isZoomEnabled = false
mapView.isScrollEnabled = false
mapView.isUserInteractionEnabled = false
顺便说一句,如果您想要一张静态地图,则可以考虑使用 MKMapSnapshotter
代替.这将创建地图的图像表示.如果您有注释或叠加层,则必须手动渲染它们,但是根据您的用例,地图快照可能会完成这项工作.
By the way, if you want a static map, you might consider using MKMapSnapshotter
instead. This creates an image representation of a map. If you have annotations or overlays, you have to render them manually, but, depending upon your use-case, map snapshots might do the job.
这篇关于如何在MKMapView上禁用用户交互?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!