eric
eric

Reputation: 4951

How to disable user interaction on MKMapView?

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.

Upvotes: 41

Views: 21675

Answers (5)

kittonian
kittonian

Reputation: 1431

I know this is a really old thread but the answer is a simple modifier of

.allowsHitTesting(false)

on the Map object.

This disables all Map interaction.

Upvotes: 0

Rob
Rob

Reputation: 438122

The key is to disable zooms and scrolls.

In Objective-C:

self.mapView.zoomEnabled = false;
self.mapView.scrollEnabled = false;
self.mapView.userInteractionEnabled = false;

Or Swift:

mapView.isZoomEnabled = false
mapView.isScrollEnabled = false
mapView.isUserInteractionEnabled = false

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.

Upvotes: 88

Adam Waite
Adam Waite

Reputation: 18855

You can do this in Interface Builder like this:

Like this

Upvotes: 21

illuminatus
illuminatus

Reputation: 2086

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

Upvotes: 1

Shamsudheen TK
Shamsudheen TK

Reputation: 31311

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.

Upvotes: 0

Related Questions