问题描述
大家好,我正试图让指南针从我的地图上消失并撞到砖墙。下面是我的地图初始化函数,我不确定变量是什么。我尝试了 mapView.compassEnabled == false
、mapView.compassView = nil
和其他一些我发现无效的方法。
感谢您的帮助!
@objc func initMap() {
if mapView != nil {
print("Attempting to init map that is already initialized,returning")
return
}
mapView = NavigationMapView(frame: UIApplication.shared.delegate!.window!!.bounds,// Todo: Set frame from react
styleURL: NSURL(string: "mapBox://styles/paway/ckcp7w04x03by1iqi1t26uilu") as URL?)
guard let mapView = self.mapView else { return }
mapView.zoomLevel = 2
mapView.delegate = self
mapView.locationManager.setdistanceFilter?(6)
PWLocationManager.shared.delegate = self
mapView.setCenter(CLLocationCoordinate2D(latitude: 37.0902,longitude: -95.7129),animated: false)
mapView.navigationMapViewDelegate = self
switch cameraMode {
case "overview":
mapCameraState = .overviewmode
mapView.userTrackingMode = .followWithheading
case "followheading":
mapCameraState = .followMode
mapView.userTrackingMode = .followWithheading
default:
mapView.userTrackingMode = .none
}
mapView.isPitchEnabled = true
mapView.showsUserLocation = true
self.addSubview(mapView)
addMapTapRecognizer()
addobservers()
}
解决方法
更新答案**
这仅适用于地图顶部的组件。如果您只有一张普通地图,我会尝试使用负边距将指南针推出视野。
我在这里找到了答案https://stackoverflow.com/a/57560116/13639051
我加了:
mapView.compassViewPosition = .bottomLeft
mapView.compassViewMargins = CGPoint(x: 0,y: 0)
将指南针隐藏在贯穿整个项目的底部吐司后面。