How to disable user interaction on MKMapView?

2019-01-17 10:25发布

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.

4条回答
男人必须洒脱
2楼-- · 2019-01-17 10:46

You can do this in Interface Builder like this:

Like this

查看更多
迷人小祖宗
3楼-- · 2019-01-17 10:51

How about this little hack! just place UIView on top of the MKMapView having all the same frame details. Also note that the backgroundColor of this view should be clearColor

查看更多
Summer. ? 凉城
4楼-- · 2019-01-17 10:52

The key is to disable zooms and scrolls, such as:

self.mapView.zoomEnabled = false;
self.mapView.scrollEnabled = false;
self.mapView.userInteractionEnabled = false;
查看更多
我命由我不由天
5楼-- · 2019-01-17 10:55

You can set the enabled property of MKAnnotationView to NO

For disabling Zoom, you can set mapView.zoomEnabled = FALSE;

enabled

A Boolean value indicating whether the annotation is enabled.

@property (nonatomic, getter=isEnabled) BOOL enabled

Discussion

The default value of this property is YES. If the value of this property is NO, the annotation view ignores touch events and cannot be selected. Subclasses may also display the annotation contents differently depending on the value of this property.

查看更多
登录 后发表回答