38

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.

eric
  • 4,863
  • 11
  • 41
  • 55
  • FYI, I tried this and the app was rejected for not being interactive. I didn't use MKMapView, so I can't actually answer your question. – Steve Mallory Mar 14 '13 at 19:08
  • @SteveMallory Shouldn't be rejected for doing this in just one use case I think. Other apps do it. Have a look at foursquare: In one use case (Shop Detail View) the map is pretty much locked in place which makes sense since the content context is a single shop. – eric Mar 14 '13 at 19:14
  • From my experience - it doesn't work when selected in interface builder by removing checkmark on "User Interaction Enabled" for the map view. However, setting it by code worked for me. – Andris Zalitis Aug 06 '14 at 20:00
  • @SteveMallory I doubt that's the main reason the app was rejected, seeing as Apple has added built in params specifically to MKMapView to allow devs to toggle these abilities on or off. Perhaps they just meant a general lack of interactivity across your whole app. – Albert Renshaw Jul 29 '16 at 13:55

4 Answers4

85

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.

Rob
  • 415,655
  • 72
  • 787
  • 1,044
  • 1
    Ok this answer worked for me, for the most part. Taps are still getting through but that doesn't break my use-case and users cannot scroll or zoom so I'm happy. Thanks! – eric Mar 14 '13 at 21:07
  • Using this, I was still able to use the two finger rotation and tilt gestures to displace the center focal point entirely out of view, though it was rather tedious. – SandWyrm Dec 13 '13 at 21:12
  • What's the point of disabling user interaction if you have to still do it in code...? – Mgamerz Sep 20 '14 at 05:46
  • 2
    Good tip! I simply set the userInteractionEnabled to false in my viewDidLoad, and that seemed to do the trick. The zoomEnabled and scrollEnabled changes may be redundant. – Octavio Antonio Cedeño Mar 07 '17 at 13:40
20

You can do this in Interface Builder like this:

Like this

Adam Waite
  • 19,175
  • 22
  • 126
  • 148
1

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

illuminatus
  • 1,986
  • 4
  • 16
  • 19
0

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.

Shamsudheen TK
  • 30,739
  • 9
  • 69
  • 102
  • I don't understand how this applies to disable interaction to the entire map. I don't want the user to be able to interact anywhere within the entire Map -- in this particular use case. – eric Mar 14 '13 at 19:11