如何禁用MKMapView上的用户交互?

时间:2023-01-23 15:08:58

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.

如何在iOS中禁用对整个映射(MKMapView)的用户交互?我只想禁用缩放、点击等功能并显示静态地图。(自我。mapView setUserInteractionEnabled没有):没有工作。通过谷歌或其他答案在堆栈上找不到有效的解决方案。针对iOS 5。应该有一种更简单的方法。

4 个解决方案

#1


62  

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

关键是禁用缩放和滚动,例如:

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

#2


17  

You can do this in Interface Builder like this:

你可以在接口构建器中这样做:

如何禁用MKMapView上的用户交互?

#3


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

这个小技巧怎么样?把UIView放在MKMapView的顶部有相同的帧细节。还要注意,这个视图的背景颜色应该是清晰的

#4


0  

You can set the enabled property of MKAnnotationView to NO

可以将MKAnnotationView的enabled属性设置为NO

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

要禁用缩放,可以设置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.

这个属性的默认值是YES。如果该属性的值为NO,则注释视图将忽略触摸事件,无法选择。子类还可以根据该属性的值不同地显示注释内容。

#1


62  

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

关键是禁用缩放和滚动,例如:

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

#2


17  

You can do this in Interface Builder like this:

你可以在接口构建器中这样做:

如何禁用MKMapView上的用户交互?

#3


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

这个小技巧怎么样?把UIView放在MKMapView的顶部有相同的帧细节。还要注意,这个视图的背景颜色应该是清晰的

#4


0  

You can set the enabled property of MKAnnotationView to NO

可以将MKAnnotationView的enabled属性设置为NO

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

要禁用缩放,可以设置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.

这个属性的默认值是YES。如果该属性的值为NO,则注释视图将忽略触摸事件,无法选择。子类还可以根据该属性的值不同地显示注释内容。