我在我的应用程序中使用MapView来显示一些注释。在iOS 7中,指南针随机出现在地图上。我无法重现错误,因为它随机出现,但我想禁用它。任何想法如何禁用它?
更新:我发现不是随机出现,而是出现在特定的手势上。当您使用2个手指并向右滑动而另一个向左滑动时。
这里快速代码:
let mapRotateGesture = UIRotationGestureRecognizer(target: self, action: "didRotateMap:")
mapRotateGesture.delegate = self
self.map.addGestureRecognizer(mapRotateGesture)
func didRotateMap(gesture: UIGestureRecognizer) {
// Removeing compass
if (gesture.state == .Began || gesture.state == .Changed) {
for view in map.subviews as! [UIView] {
if view.isKindOfClass(NSClassFromString("MKCompassView")) {
view.removeFromSuperview()
}
}
}
}
您可以在旋转地图时通过在所有iOS中的viewDidLoad方法中添加以下行来隐藏MKMapView上的指南针:
[self.mapView setLayoutMargins:UIEdgeInsetsMake(-50, 0, -50, 0)];
完全隐藏指南针,不旋转地图
mapView.allowsRotating = false
Swift 4,Mapbox-iOS-SDK(4.9.0)
据我所知,你想要的是禁止显示用户的当前位置。你应该使用@property(非原子)BOOL showsUserLocation。 Docs on this
假设@property(非原子)MKUserTrackingMode userTrackingMode无法启用或禁用跟踪,它只是更改不跟随,跟随和跟随旋转之间的模式。