How to Disable User Interaction on Mkmapview

How to disable user interaction on MKMapView?

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.

Disable all user interaction for MKMapView except for a given MKAnnotationView

On the mapView, set scrollEnabled, zoomEnabled, pitchEnabled, and rotateEnabled to NO and leave userInteractionEnabled as YES.

This way, the annotation views will still be enabled.

For pitchEnabled and rotateEnabled, you may want to check if those properties exist before setting them (eg. check if the map view respondsToSelector:@selector(setPitchEnabled), etc.) since they were added in iOS 7.

Hiding and disabling user interaction on a MapKit pin?

The enabled property of MKAnnotationView can be set to NO to disable selection as the documentation states:

If the value of this property is NO, the annotation view ignores touch events and cannot be selected.

Disable touch events while MKMapview is doing SetRegion Animated function call

The setRegion initiates the animated update, which will not complete, and most likely will not even start after executing the setRegion line in your code. It happens asynchronously.

That means disabling and and re-enabling user interactions has no effect.

In your controller you need to handle the following MKMapViewDelegate callbacks:

mapView(_:regionWillChangeAnimated:)

mapView(_:regionDidChangeAnimated:)

Disable user interaction and/or map updates before animation starts and enable when it is done.

Disable touches on MKAnnotationView

As mentioned in a previous answer (and the documentation), to disable touches on an annotation view, you can set its enabled property to NO.


Setting canShowCallout to NO is a potential alternative. However, that will not prevent the didSelectAnnotationView and didDeselectAnnotationView delegate methods from still getting called (even though the callout will not be displayed). That may be an issue depending on your situation.

Disable user interaction form MapView in react-native

Edit: MapView has been removed for React Native, you can find the new docs over at react-community/react-native-maps/. Thanks @Siraj for pointing this out!

You can use the differents props MapView has to disable interaction:

pitchEnabled

rotateEnabled

scrollEnabled

zoomEnabled

If you feel it's not enough, feel free to submit a PR to React native to implement userInteraction as a prop directly.

MKMapView in table cell: Make whole cell clickable

Try disabling everything inside the cell

for(UIView * cellSubviews in cell.subviews)
{
cellSubviews.userInteractionEnabled = NO;
}


Related Topics



Leave a reply



Submit